List of usage examples for javax.crypto.spec DHPrivateKeySpec DHPrivateKeySpec
public DHPrivateKeySpec(BigInteger x, BigInteger p, BigInteger g)
x
, a prime modulus p
, and a base generator g
. From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Decode a DH private key.// ww w. j av a 2 s . co m * * @param encodedKey private key to decode * @param parameters DH parameters used in decoding * @return decoded private key * @throws NoSuchAlgorithmException if DH algorithm is unavailable * @throws InvalidKeySpecException if unable to build a valid DH key spec */ public static DHPrivateKey decodePrivateKey(String encodedKey, DHParameterSpec parameters) throws NoSuchAlgorithmException, InvalidKeySpecException { byte[] keyBytes = Base64.decodeBase64(encodedKey.getBytes()); DHPrivateKeySpec keySpec = new DHPrivateKeySpec(new BigInteger(keyBytes), parameters.getP(), parameters.getG()); KeyFactory keyFactory = KeyFactory.getInstance("DH"); return (DHPrivateKey) keyFactory.generatePrivate(keySpec); }