Example usage for javax.crypto.spec DHPrivateKeySpec DHPrivateKeySpec

List of usage examples for javax.crypto.spec DHPrivateKeySpec DHPrivateKeySpec

Introduction

In this page you can find the example usage for javax.crypto.spec DHPrivateKeySpec DHPrivateKeySpec.

Prototype

public DHPrivateKeySpec(BigInteger x, BigInteger p, BigInteger g) 

Source Link

Document

Constructor that takes a private value x, a prime modulus p, and a base generator g.

Usage

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