Example usage for org.bouncycastle.jce.netscape NetscapeCertRequest sign

List of usage examples for org.bouncycastle.jce.netscape NetscapeCertRequest sign

Introduction

In this page you can find the example usage for org.bouncycastle.jce.netscape NetscapeCertRequest sign.

Prototype

public void sign(PrivateKey priv_key) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException,
            NoSuchProviderException, InvalidKeySpecException 

Source Link

Usage

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;
}