Package javax.crypto

Examples of javax.crypto.Mac.update()


            n >>>= 8;
        }

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

        return mac.doFinal();
    }

}
View Full Code Here


           
            //EtM Composition Approach
            int macLenght = mac.getMacLength();
            byte[] secure = new byte[cipher.getOutputSize(insecure.length)+ macLenght];
            int secureCount = cipher.doFinal(insecure,0,insecure.length,secure);
            mac.update(secure, 0, secureCount);
            mac.doFinal(secure, secureCount);
                       
            return secure;
        }
        catch (Exception e)
View Full Code Here

                log.debug("decrypting w/ " + algorithm + "/" + algorithmParams);
            }

            //EtM Composition Approach
            int macLenght = mac.getMacLength();
            mac.update(secure, 0, secure.length-macLenght);
            byte[] signedDigestHash = mac.doFinal();

            boolean isMacEqual = true;
            for (int i = 0; i < signedDigestHash.length; i++)
            {
View Full Code Here

  public static void hmacSha1Verify(byte[] key, byte[] in, byte[] expected)
  throws GeneralSecurityException {
    Mac hmac = Mac.getInstance(HMAC_TYPE);
    Key hmacKey = new SecretKeySpec(key, HMAC_TYPE);
    hmac.init(hmacKey);
    hmac.update(in);
    byte actual[] = hmac.doFinal();
    if (actual.length != expected.length) {
      throw new GeneralSecurityException("HMAC verification failure");
    }
    for (int i=0; i < actual.length; i++) {
View Full Code Here

          + MIN_HMAC_KEY_LEN + " bytes.");
    }
    Mac hmac = Mac.getInstance(HMAC_TYPE);
    Key hmacKey = new SecretKeySpec(key, HMAC_TYPE);
    hmac.init(hmacKey);
    hmac.update(in);
    return hmac.doFinal();
  }
 
  /**
   * Verifies an HMAC SHA1 hash.  Throws if the verification fails.
View Full Code Here

     */
    private static byte[] authenticationTransform(byte[] passcode) {
        try {
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(bytesToKey(KEY1));
            mac.update(passcode);
            return mac.doFinal();

        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Can't generate Authentication Key", e);

View Full Code Here

    private static byte[] privateKeyTransform(byte[] passcode,
            int keysizeInBytes) {
        try {
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(bytesToKey(KEY4));
            mac.update(passcode);

            byte[] block_0 = mac.doFinal();
            byte[] output = null;

            if (block_0.length < keysizeInBytes) {
View Full Code Here

                    byte[] key = (byte[]) block_n_1.clone();
                    key[0] = (byte) (key[0] & (0xff ^ KEY4[0]));

                    mac.init(bytesToKey(key));
                    mac.update(passcode);

                    block_n = mac.doFinal();

                    byte[] output2 = new byte[output.length + block_n.length];
View Full Code Here

           
            //EtM Composition Approach
            int macLenght = mac.getMacLength();
            byte[] secure = new byte[cipher.getOutputSize(insecure.length)+ macLenght];
            int secureCount = cipher.doFinal(insecure,0,insecure.length,secure);
            mac.update(secure, 0, secureCount);
            mac.doFinal(secure, secureCount);
                       
            return secure;
        }
        catch (Exception e)
View Full Code Here

                log.fine("decrypting w/ " + algorithm + "/" + algorithmParams);
            }

            //EtM Composition Approach
            int macLenght = mac.getMacLength();
            mac.update(secure, 0, secure.length-macLenght);
            byte[] signedDigestHash = mac.doFinal();

            boolean isMacEqual = true;
            for (int i = 0; i < signedDigestHash.length; i++)
            {
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.