Examples of Mac


Examples of javax.crypto.Mac

        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

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

Examples of javax.crypto.Mac

        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

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

Examples of javax.crypto.Mac

        assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
    }

    @Test
    public void testInitializedMac() throws IOException {
        final Mac md5Mac = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, STANDARD_KEY_BYTES);
        final Mac md5Mac2 = HmacUtils.getInitializedMac("HmacMD5", STANDARD_KEY_BYTES);
        Assert.assertArrayEquals(STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac, STANDARD_PHRASE_STRING)
                .doFinal());
        Assert.assertArrayEquals(STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac2, STANDARD_PHRASE_STRING)
                .doFinal());
    }
View Full Code Here

Examples of javax.crypto.Mac

   /*----------------------------------------------------------------base64Url-+
   *//**
   *//*
   +-------------------------------------------------------------------------*/
   static private String hashKey(String in) throws Exception {
      Mac mac = Mac.getInstance(ALGO);
      mac.init(new SecretKeySpec(paySecret.getBytes(ENC), ALGO));
      return base64Url(mac.doFinal(in.getBytes(ENC)));
   }
View Full Code Here

Examples of javax.crypto.Mac

  }

  private String sign(String data, String key) {
    try {
      SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(ENCODING), SIGNATURE_METHOD);
      Mac mac = Mac.getInstance(SIGNATURE_METHOD);
      mac.init(signingKey);
      byte[] rawHmac = mac.doFinal(data.getBytes(ENCODING));
      return Base64.encodeBytes(rawHmac);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

Examples of javax.crypto.Mac

    byte[] hash = digest.digest(data[data.length - 1]);
    return new Sha256Hash(hash);
  }

  public static Mac buildHmacSha1(SecretKey key) {
    Mac mac = getHmacSha1();
    try {
      mac.init(key);
    } catch (InvalidKeyException e) {
      throw new IllegalStateException("Unexpected encryption error", e);
    }
    return mac;
  }
View Full Code Here

Examples of javax.crypto.Mac

    }
    return mac;
  }

  public static Mac buildHmacSha256(SecretKey key) {
    Mac mac = getHmacSha256();
    try {
      mac.init(key);
    } catch (InvalidKeyException e) {
      throw new IllegalStateException("Unexpected encryption error", e);
    }
    return mac;
  }
View Full Code Here

Examples of javax.crypto.Mac

    SecretKeySpec signingKey = new SecretKeySpec(keyData, HMAC_SHA256_ALGORITHM);
    return signingKey;
  }

  public static byte[] hmacSha1(SecretKeySpec signingKey, byte[]... data) {
    Mac mac = buildHmacSha1(signingKey);

    return computeMac(mac, data);
  }
View Full Code Here

Examples of javax.crypto.Mac

    return computeMac(mac, data);
  }

  public static byte[] hmacSha256(SecretKeySpec signingKey, byte[]... data) {
    Mac mac = buildHmacSha256(signingKey);

    return computeMac(mac, data);
  }
View Full Code Here

Examples of javax.crypto.Mac

    byte[] hash = mac.doFinal(data[data.length - 1]);
    return hash;
  }

  public static byte[] hmacSha1(SecretKeySpec signingKey, byte[] buffer, int offset, int length) {
    Mac mac = buildHmacSha1(signingKey);

    mac.update(buffer, offset, length);
    byte[] hash = mac.doFinal();
    return hash;
  }
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.