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