List of usage examples for javax.crypto.spec DHParameterSpec getP
public BigInteger getP()
p
. From source file:Main.java
public static void main(String[] argv) throws Exception { AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH"); paramGen.init(1024);// w w w. j a v a2s. c o m AlgorithmParameters params = paramGen.generateParameters(); DHParameterSpec dhSpec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class); System.out.println("" + dhSpec.getP() + "," + dhSpec.getG() + "," + dhSpec.getL()); }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Decode a DH public key./* www . j ava 2 s . c o m*/ * * @param encodedKey public key to decode * @param parameters DH parameters used in decoding * @return decoded public key * @throws NoSuchAlgorithmException if DH algorithm is unavailable * @throws InvalidKeySpecException if unable to build a valid DH key spec */ public static DHPublicKey decodePublicKey(String encodedKey, DHParameterSpec parameters) throws NoSuchAlgorithmException, InvalidKeySpecException { byte[] keyBytes = Base64.decodeBase64(encodedKey.getBytes()); DHPublicKeySpec keySpec = new DHPublicKeySpec(new BigInteger(keyBytes), parameters.getP(), parameters.getG()); KeyFactory keyFactory = KeyFactory.getInstance("DH"); return (DHPublicKey) keyFactory.generatePublic(keySpec); }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Decode a DH private key./*w ww . j a va2 s . com*/ * * @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); }
From source file:edu.internet2.middleware.openid.message.impl.AssociationRequestMarshaller.java
/** {@inheritDoc} */ protected void marshallParameters(AssociationRequest request, ParameterMap parameters) { parameters.put(Parameter.assoc_type.QNAME, request.getAssociationType().toString()); SessionType sessionType = request.getSessionType(); parameters.put(Parameter.session_type.QNAME, sessionType.toString()); if (sessionType.equals(SessionType.DH_SHA1) || sessionType.equals(SessionType.DH_SHA256)) { DHParameterSpec dhParameters = request.getDHParameters(); if (dhParameters != null) { byte[] modulus = Base64.encodeBase64(dhParameters.getP().toByteArray()); parameters.put(Parameter.dh_modulus.QNAME, new String(modulus)); byte[] gen = Base64.encodeBase64(dhParameters.getG().toByteArray()); parameters.put(Parameter.dh_gen.QNAME, new String(gen)); }//from ww w.j a v a 2 s .c o m DHPublicKey consumerPublic = request.getDHConsumerPublic(); if (consumerPublic != null) { String publicKey = EncodingUtils.encodePublicKey(consumerPublic); parameters.put(Parameter.dh_consumer_public.QNAME, publicKey); } } }
From source file:org.apache.abdera2.common.security.DHBase.java
private void init() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidParameterSpecException, InvalidKeySpecException { AlgorithmParameterGenerator pgen = AlgorithmParameterGenerator.getInstance("DH"); pgen.init(512);/*from w ww. j a v a2s . co m*/ AlgorithmParameters params = pgen.generateParameters(); DHParameterSpec dhspec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class); KeyPairGenerator keypairgen = KeyPairGenerator.getInstance("DH"); keypairgen.initialize(dhspec); keyPair = keypairgen.generateKeyPair(); p = dhspec.getP(); g = dhspec.getG(); l = dhspec.getL(); }