Search in sources :

Example 6 with ECPrivateKeySpec

use of org.bouncycastle.jce.spec.ECPrivateKeySpec in project habot by ghys.

the class Utils method loadPrivateKey.

/**
 * Load the private key from a URL-safe base64 encoded string
 *
 * @param encodedPrivateKey
 * @return
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public static PrivateKey loadPrivateKey(String encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
    byte[] decodedPrivateKey = base64Decode(encodedPrivateKey);
    BigInteger s = BigIntegers.fromUnsignedByteArray(decodedPrivateKey);
    ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(CURVE);
    ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(s, parameterSpec);
    KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, PROVIDER_NAME);
    return keyFactory.generatePrivate(privateKeySpec);
}
Also used : ECPrivateKeySpec(org.bouncycastle.jce.spec.ECPrivateKeySpec) ECNamedCurveParameterSpec(org.bouncycastle.jce.spec.ECNamedCurveParameterSpec) BigInteger(java.math.BigInteger) KeyFactory(java.security.KeyFactory)

Aggregations

ECPrivateKeySpec (org.bouncycastle.jce.spec.ECPrivateKeySpec)6 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)5 ECParameterSpec (org.bouncycastle.jce.spec.ECParameterSpec)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 KeyFactory (java.security.KeyFactory)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 PrivateKey (java.security.PrivateKey)2 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)2 PrivateKeyInfo (org.bouncycastle.asn1.pkcs.PrivateKeyInfo)2 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)2 BCECPrivateKey (org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey)2 PEMException (org.bouncycastle.openssl.PEMException)2 PEMKeyPair (org.bouncycastle.openssl.PEMKeyPair)2 PEMParser (org.bouncycastle.openssl.PEMParser)2 JcaPEMKeyConverter (org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter)2 ByteString (com.google.protobuf.ByteString)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1