Examples of Mac


Examples of javax.crypto.Mac

        try {
            this.macAlgorithm.init(secretKey);
        } catch (InvalidKeyException ex) {
            // reinstantiate Mac object to work around bug in JDK
            // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
            Mac mac = this.macAlgorithm;
            try {
                this.macAlgorithm = Mac.getInstance(macAlgorithm.getAlgorithm());
            } catch (Exception e) {
                // this shouldn't occur, but if it does, restore previous Mac
                if (log.isDebugEnabled()) {
View Full Code Here

Examples of javax.crypto.Mac

        /**
         * Make sure that we can generate the  Mac.
         */
        try {
            Mac mac = Mac.getInstance(algorithm);
            mac.init(key);
        } catch (NoSuchAlgorithmException e) {
            assert false : "Should never have reached here";
        } catch (InvalidKeyException e) {
            assert false : "Should never have reached here";
        }
View Full Code Here

Examples of javax.crypto.Mac

            bytes[i] = (byte) (n);
            n >>>= 8;
        }

        try {
            Mac mac = Mac.getInstance(algorithm);
            mac.init(key);
            mac.update(bytes);

            return mac.doFinal();
        } catch (NoSuchAlgorithmException e) {
            //shouldn't happen
        } catch (InvalidKeyException e) {
            //shouldn't happen
        }
View Full Code Here

Examples of javax.crypto.Mac

     * @throws InvalidKeyException
     * @throws UnsupportedEncodingException
     */
    private Mac getMac(int keyNo) throws NoSuchAlgorithmException, InvalidKeyException,
            UnsupportedEncodingException {
        Mac m = Mac.getInstance("HmacSHA256");
        m.init(getKey(keyNo));
        return m;
    }
View Full Code Here

Examples of javax.crypto.Mac

                + "in the Web Console");
        }
        byte[] b = new byte[20];
        random.nextBytes(b);
        final SecretKey secretKey = new SecretKeySpec(b, HMAC_SHA1);
        final Mac m = Mac.getInstance(HMAC_SHA1);
        m.init(secretKey);
        m.update(UTF_8.getBytes(UTF_8));
        m.doFinal();
    }
View Full Code Here

Examples of javax.crypto.Mac

            UnsupportedEncodingException, NoSuchAlgorithmException,
            InvalidKeyException {

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

Examples of javax.crypto.Mac

        }
    }

    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

Examples of javax.crypto.Mac

     */
   
    public static VerificationResult verifySubscriptionPostRequestSignature(String clientSecret, byte[] rawJsonData, String xHubSignature) throws InstagramException{
      SecretKeySpec keySpec;
    keySpec = new SecretKeySpec(clientSecret.getBytes(Charset.forName("UTF-8")), HMAC_SHA1);
      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

Examples of javax.crypto.Mac

    public static String signature(String clientSecret, String message) throws InstagramException {
        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

Examples of javax.crypto.Mac

                        new ByteArrayInputStream("what do ya want for nothing?".getBytes())));
    }

    @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()));
    }
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.