Examples of DHParameterSpec


Examples of javax.crypto.spec.DHParameterSpec

        assertNotNull(keyPair);
    }

    public void testGenerateKeyPairSha256Random()
    {
        DHParameterSpec parameterSpec = DiffieHellmanSession.generateRandomParameter(512, 256);

        KeyPair keyPair = DiffieHellmanSession.generateKeyPair(parameterSpec);

        assertNotNull(keyPair);
    }
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

        assertNotNull(keyPair);
    }

    public void testPublicKeyConversion() throws AssociationException
    {
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.getDefaultParameter();

        DiffieHellmanSession diffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA1, dhParameterSpec);

        String publicKeyBase64 = diffieHellmanSession.getPublicKey();
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

        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();
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

        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();
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

        testEncryptDecryptMacKey(consumerDiffieHellmanSession, macKey);
    }

    public void testEncryptDecryptMacKeySha256Random() throws GeneralSecurityException, AssociationException
    {
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.generateRandomParameter(512, 256);

        assertNotNull(dhParameterSpec);

        DiffieHellmanSession consumerDiffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA256, dhParameterSpec);
        byte[] macKey = Association.generateMacKey(Association.HMAC_SHA256_ALGORITHM, Association.HMAC_SHA256_KEYSIZE).getEncoded();
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

        }
    }

    public void testPublicKey() throws AssociationException
    {
        DHParameterSpec dhParameterSpec = DiffieHellmanSession.getDefaultParameter();

        DiffieHellmanSession diffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA1, dhParameterSpec);

        String dhPublicKeyBase64 = diffieHellmanSession.getPublicKey();

        DHPublicKey dhPublicKey = diffieHellmanSession.stringToPublicKey(dhPublicKeyBase64);

        BigInteger two = new BigInteger("2");
        BigInteger y = dhPublicKey.getY();
        BigInteger p = dhParameterSpec.getP();

        assertTrue(y.compareTo(two) != -1);
        assertTrue(y.compareTo(p) == -1);
    }
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

   *
   * @return dh keypair
   */
  protected KeyPair generateKeyPair() {
    KeyPair keyPair = null;
    DHParameterSpec keySpec = new DHParameterSpec(DH_MODULUS, DH_BASE);
    try {
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
      keyGen.initialize(keySpec);
      keyPair = keyGen.generateKeyPair();
      keyAgreement = KeyAgreement.getInstance("DH");
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

    public void init(BigInteger p, BigInteger g)
            throws GeneralSecurityException {
        this.p = p;
        this.g = g;
        generator.initialize(new DHParameterSpec(p, g));
        final KeyPair kp = generator.generateKeyPair();
        agreement.init(kp.getPrivate());
        e = ((javax.crypto.interfaces.DHPublicKey) kp.getPublic()).getY();
    }
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

        return elSpec;
    }

    public DHParameterSpec getParams()
    {
        return new DHParameterSpec(elSpec.getP(), elSpec.getG());
    }
View Full Code Here

Examples of javax.crypto.spec.DHParameterSpec

    JCEDHPrivateKey(
        DHPrivateKeySpec    spec)
    {
        this.x = spec.getX();
        this.dhSpec = new DHParameterSpec(spec.getP(), spec.getG());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.