List of usage examples for org.bouncycastle.jce.netscape NetscapeCertRequest sign
public void sign(PrivateKey priv_key) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, NoSuchProviderException, InvalidKeySpecException
From source file:android.webkit.CertTool.java
License:Apache License
static String getSignedPublicKey(Context context, int index, String challenge) { try {/*from www .ja v a2 s. c o 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; }