Code example for DHParameterSpec

Methods: getG, getP

0
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.getDefaultParameter();
 
        assertNotNull(dhParameterSpec);
 
        DiffieHellmanSession consumerDiffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA1, dhParameterSpec);
        byte[] macKey = Association.generateMacKey(Association.HMAC_SHA1_ALGORITHM, Association.HMAC_SHA1_KEYSIZE).getEncoded();
 
        testEncryptDecryptMacKey(consumerDiffieHellmanSession, macKey);
    } 
 
    public void testEncryptDecryptMacKeySha1Random() throws GeneralSecurityException, AssociationException 
    { 
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.generateRandomParameter(512, 256);
 
        assertNotNull(dhParameterSpec);
 
        DiffieHellmanSession consumerDiffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA1, dhParameterSpec);
        byte[] macKey = Association.generateMacKey(Association.HMAC_SHA1_ALGORITHM, Association.HMAC_SHA1_KEYSIZE).getEncoded();
 
        testEncryptDecryptMacKey(consumerDiffieHellmanSession, macKey);
    } 
 
    public void testEncryptDecryptMacKeySha256() throws GeneralSecurityException, AssociationException 
    { 
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.getDefaultParameter();
 
        assertNotNull(dhParameterSpec);
 
        DiffieHellmanSession consumerDiffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA256, dhParameterSpec);
        byte[] macKey = Association.generateMacKey(Association.HMAC_SHA256_ALGORITHM, Association.HMAC_SHA256_KEYSIZE).getEncoded();
 
        testEncryptDecryptMacKey(consumerDiffieHellmanSession, macKey);
    } 
 
    public void testEncryptDecryptMacKeySha256Random() throws GeneralSecurityException, AssociationException 
    {