Package javax.crypto

Examples of javax.crypto.Mac.doFinal()


            key = this.key;
        }
        Mac mac = Mac.getInstance(MAC_NAME);
        mac.init(key);
        byte[] text = baseString.getBytes(ENCODING);
        return mac.doFinal(text);
    }

    /** ISO-8859-1 or US-ASCII would work, too. */
    private static final String ENCODING = OAuth.ENCODING;

View Full Code Here


    String message = "/" + restInvocation.getPath() + "\000" + restInvocation.getRequestBody();

    Mac mac = getMac();
    mac.update(message.getBytes());

    return Base64.encodeBytes((String.format("%064x", new BigInteger(1, mac.doFinal())).getBytes()));
  }
}
View Full Code Here

    byte[] key = secret.getBytes();
    SecretKey hmacKey = new SecretKeySpec(key, "HMACSHA256");
    Mac mac = Mac.getInstance("HMACSHA256");
    mac.init(hmacKey);
    byte[] digest = mac.doFinal(encoded_envelope.getBytes());

    return envelope;

  }
View Full Code Here

            // Create the message authentication code (MAC)
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signingKey);

            // Compute the HMAC value
            result = mac.doFinal(source.getBytes());
        } catch (NoSuchAlgorithmException nsae) {
            throw new RuntimeException(
                    "Could not find the SHA-1 algorithm. HMac conversion failed.",
                    nsae);
        } catch (InvalidKeyException ike) {
View Full Code Here

        mac.reset();

        mac.update(message, 0, message.length);

        out = mac.doFinal();

        if (!areEqual(out, output))
        {
            fail("Failed - expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out)));
        }
View Full Code Here

        mac.init(kGen.generateKey());

        mac.update(message);

        out = mac.doFinal();
    }

    private void testExceptions()
        throws Exception
    {
View Full Code Here

        key.setTryWrongPKCS12Zero(wrongPkcs12Zero);

        Mac mac = Mac.getInstance(oid.getId(), "BC");
        mac.init(key, defParams);
        mac.update(data);
        return mac.doFinal();
    }
   
    public static class BCPKCS12KeyStore
        extends JDKPKCS12KeyStore
    {
View Full Code Here

        mac.reset();
       
        mac.update(message, 0, message.length);

        out = mac.doFinal();

        if (!arrayEquals(out, output))
        {
            fail("Failed - expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out)));
        }
View Full Code Here

        try {
            SecretKeySpec signingKey = new SecretKeySpec(stringToBytes(key),
                    SIGNATURE_METHOD);
            Mac mac = Mac.getInstance(SIGNATURE_METHOD);
            mac.init(signingKey);
            byte[] rawSignature = mac.doFinal(stringToBytes(data));
            result = bytesToString(encode(rawSignature));
            result = result.trim();
        } catch (Exception e) {
            throw new SignatureException("Failed to generate HMAC : "
                    + e.getMessage());
View Full Code Here

            mac.init(key);

            mac.update(input, 0, input.length);

            byte[] out = mac.doFinal();
            if (!areEqual(out, ref))
            {
                fail("Failed - expected " + new String(Hex.encode(ref)) + " got " + new String(Hex.encode(out)));
            }
        }
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.