Package javax.crypto

Examples of javax.crypto.Mac.doFinal()


        String cookiePayload = String.valueOf(token) + String.valueOf(expires)
            + "@" + userId;
        Mac m = Mac.getInstance(HMAC_SHA1);
        m.init(key);
        m.update(cookiePayload.getBytes(UTF_8));
        String cookieValue = byteToHex(m.doFinal());
        return cookieValue + "@" + cookiePayload;
    }

    /**
     * Splits the authentication data into the three parts packed together while
View Full Code Here


    private static byte[] hmac(final String message, final String secretKey, final String hashAlgorithm) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
        final SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), hashAlgorithm);
        final Mac mac = Mac.getInstance(hashAlgorithm);
        mac.init(secretKeySpec);
        return mac.doFinal(message.getBytes("UTF-8"));
    }

}
View Full Code Here

      Mac mac;
     
      try {
      mac = Mac.getInstance(HMAC_SHA1);
      mac.init(keySpec);
      byte[] result = mac.doFinal(rawJsonData);
      String encodedResult = Hex.encodeHexString(result);
     
      return new VerificationResult(encodedResult.equals(xHubSignature), encodedResult);
      } catch (NoSuchAlgorithmException e) {
      throw new InstagramException("Invalid algorithm name!", e);
View Full Code Here

        SecretKeySpec keySpec = new SecretKeySpec(clientSecret.getBytes(Charset.forName("UTF-8")), HMAC_SHA256);

        try {
            Mac mac = Mac.getInstance(HMAC_SHA256);
            mac.init(keySpec);
            byte[] result = mac.doFinal(message.getBytes(Charset.forName("UTF-8")));
            String encodedResult = Hex.encodeHexString(result);
            return encodedResult;
        } catch (NoSuchAlgorithmException e) {
            throw new InstagramException("Invalid algorithm name!", e);
        } catch (InvalidKeyException e) {
View Full Code Here

    @Test
    public void testHmacSha1UpdateWithByteArray() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
        HmacUtils.updateHmac(mac, STANDARD_PHRASE_BYTES);
        assertEquals(STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
        HmacUtils.updateHmac(mac, "".getBytes());
        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
View Full Code Here

    public void testHmacSha1UpdateWithByteArray() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
        HmacUtils.updateHmac(mac, STANDARD_PHRASE_BYTES);
        assertEquals(STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
        HmacUtils.updateHmac(mac, "".getBytes());
        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
    public void testHmacSha1UpdateWithInpustream() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
View Full Code Here

    @Test
    public void testHmacSha1UpdateWithInpustream() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
        HmacUtils.updateHmac(mac, new ByteArrayInputStream(STANDARD_PHRASE_BYTES));
        assertEquals(STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
        HmacUtils.updateHmac(mac, new ByteArrayInputStream("".getBytes()));
        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
View Full Code Here

    public void testHmacSha1UpdateWithInpustream() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
        HmacUtils.updateHmac(mac, new ByteArrayInputStream(STANDARD_PHRASE_BYTES));
        assertEquals(STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
        HmacUtils.updateHmac(mac, new ByteArrayInputStream("".getBytes()));
        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
    public void testHmacSha1UpdateWithString() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
View Full Code Here

    @Test
    public void testHmacSha1UpdateWithString() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
        HmacUtils.updateHmac(mac, STANDARD_PHRASE_STRING);
        assertEquals(STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
        HmacUtils.updateHmac(mac, "");
        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
View Full Code Here

    public void testHmacSha1UpdateWithString() throws IOException {
        final Mac mac = HmacUtils.getHmacSha1(STANDARD_KEY_BYTES);
        HmacUtils.updateHmac(mac, STANDARD_PHRASE_STRING);
        assertEquals(STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
        HmacUtils.updateHmac(mac, "");
        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
    public void testInitializedMac() throws IOException {
        final Mac md5Mac = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, STANDARD_KEY_BYTES);
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.