Package com.CryptoAlgorithms.DiffieHellman

Examples of com.CryptoAlgorithms.DiffieHellman.DHAgreementModel


    @Test
    public void shouldFinalizeDHAgreement() throws Exception {
        DHAgreementResponse serverDHResponse = initializeDHAgreement();

        DHAgreementModel localDHAgreementModel = dhAlgorithm.generateInitialNumbers(serverDHResponse.getP(), serverDHResponse.getG());
        FinalizeDHRequest finalizeDHRequest = new FinalizeDHRequest(serverDHResponse.getKeyExchangeSessionId(), localDHAgreementModel.getPublicA());

        DefaultResponse defaultResponse = finalizeDHAgreement(finalizeDHRequest);
    }
View Full Code Here


        this.dhAlgorithm = new DHAlgorithm();
    }

    @Test
    public void shouldGenerateInitialNumbers() throws CreatingDHAgreementException {
        DHAgreementModel dhAgreementModel = dhAlgorithm.generateInitialNumbers();
        int certainty = Integer.MAX_VALUE;
        boolean isPrime = dhAgreementModel.getP().isProbablePrime(certainty);
        Assert.assertThat(isPrime, equalTo(true));
    }
View Full Code Here

        Assert.assertThat(isPrime, equalTo(true));
    }

    @Test
    public void shouldGenerateSameSecretForBoth() throws CreatingDHAgreementException, InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException {
        DHAgreementModel A = dhAlgorithm.generateInitialNumbers();
        DHAgreementModel B = dhAlgorithm.generateInitialNumbers(A.getP(), A.getG());

        byte[] server = dhAlgorithm.generateSecret(A.get_a(), B.getPublicA());
        byte[] client = dhAlgorithm.generateSecret(B.get_a(), A.getPublicA());

        MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
        byte[] digestServer = messageDigest.digest(server);
        byte[] digestClient = messageDigest.digest(client);
View Full Code Here

        Assert.assertThat(digestClient, equalTo(digestServer));
    }

    @Test
    public void shouldFailGeneratingKeyWithWrongKey() throws CreatingDHAgreementException, InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException {
        DHAgreementModel A = dhAlgorithm.generateInitialNumbers();
        DHAgreementModel B = dhAlgorithm.generateInitialNumbers();

        expectedException.expect(CreatingDHAgreementException.class);
        byte[] server = dhAlgorithm.generateSecret(A.get_a(), B.getPublicA());
    }
View Full Code Here

    @RequestMapping(value = "/initialize", method = RequestMethod.GET)
    @ResponseBody
    public Response initializeExchange() {
        try {
            DHAgreementModel dhAgreementModel = dhAlgorithm.generateInitialNumbers();
            UUID keyExchangeSessionId = UUID.randomUUID();
            keyExchangeSessions.put(keyExchangeSessionId, dhAgreementModel);
            return new DHAgreementResponse(dhAgreementModel.getP(), dhAgreementModel.getG(), dhAgreementModel.getPublicA(), keyExchangeSessionId);
        } catch (CreatingDHAgreementException e) {
            return new ErrorResponse(e.getMessage());
        }
    }
View Full Code Here

    public Response finalizeExchange(@RequestBody(required = true) FinalizeDHRequest finalizeDHRequest) {
        if (finalizeDHRequest.getKeyExchangeSessionId() == null || !keyExchangeSessions.containsKey(finalizeDHRequest.getKeyExchangeSessionId())) {
            return new ErrorResponse("Invalid keyExchangeSessionId.");
        }

        DHAgreementModel dhAgreementModel = keyExchangeSessions.get(finalizeDHRequest.getKeyExchangeSessionId());
        try {
            byte[] secretKey = dhAlgorithm.generateSecret(dhAgreementModel.get_a(), finalizeDHRequest.getPublicB());
            secretKeys.put(finalizeDHRequest.getKeyExchangeSessionId(), secretKey);
            keyExchangeSessions.remove(finalizeDHRequest.getKeyExchangeSessionId());

            return new DefaultResponse();
        } catch (CreatingDHAgreementException e) {
View Full Code Here

TOP

Related Classes of com.CryptoAlgorithms.DiffieHellman.DHAgreementModel

Copyright © 2018 www.massapicom. 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.