List of usage examples for org.bouncycastle.jce.netscape NetscapeCertRequest NetscapeCertRequest
public NetscapeCertRequest(String challenge, AlgorithmIdentifier signing_alg, PublicKey pub_key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
From source file:android.webkit.CertTool.java
License:Apache License
static String getSignedPublicKey(Context context, int index, String challenge) { try {// w w w. ja v a 2 s . co m KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); generator.initialize((index == 0) ? 2048 : 1024); KeyPair pair = generator.genKeyPair(); NetscapeCertRequest request = new NetscapeCertRequest(challenge, MD5_WITH_RSA, pair.getPublic()); request.sign(pair.getPrivate()); byte[] signed = request.toASN1Object().getDEREncoded(); Credentials.getInstance().install(context, pair); return new String(Base64.encode(signed)); } catch (Exception e) { Log.w(LOGTAG, e); } return null; }
From source file:org.jruby.ext.openssl.NetscapeSPKI.java
License:LGPL
@JRubyMethod public IRubyObject sign(final IRubyObject key, IRubyObject digest) { String keyAlg = ((PKey) key).getAlgorithm(); String digAlg = ((Digest) digest).getShortAlgorithm(); final ASN1ObjectIdentifier alg = ASN1.getOIDLookup(getRuntime()) .get(keyAlg.toLowerCase() + "-" + digAlg.toLowerCase()); try {//from w ww. j a v a2 s. c o m // NetscapeCertRequest requires "BC" provider. OpenSSLReal.doWithBCProvider(new OpenSSLReal.Runnable() { public void run() throws GeneralSecurityException { cert = new NetscapeCertRequest(challenge.toString(), new AlgorithmIdentifier(alg), ((PKey) public_key).getPublicKey()); cert.sign(((PKey) key).getPrivateKey()); } }); } catch (GeneralSecurityException gse) { throw newSPKIError(getRuntime(), gse.getMessage()); } return this; }