Code example for DHParameterSpec

Methods: getG

0
        assertNotNull(keyPair);
    } 
 
    public void testPublicKeyConversion() throws AssociationException 
    { 
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.getDefaultParameter();
 
        DiffieHellmanSession diffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA1, dhParameterSpec);
 
        String publicKeyBase64 = diffieHellmanSession.getPublicKey();
 
        assertNotNull(publicKeyBase64);
 
        DHPublicKey publicKey = diffieHellmanSession.stringToPublicKey(publicKeyBase64);
 
        assertNotNull(publicKey);
        assertEquals(publicKeyBase64, DiffieHellmanSession.publicKeyToString(publicKey));
    } 
 
    public void testEncryptDecryptMacKeySha1() throws GeneralSecurityException, AssociationException 
    { 
        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 
    {