MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / create

Method create

CodenameOne/src/com/codename1/security/Hmac.java:69–89  ·  view source on GitHub ↗
(String algorithm, byte[] key)

Source from the content-addressed store, hash-verified

67 /// is no enforced minimum but for security 128-256 bits of entropy is
68 /// recommended.
69 public static Hmac create(String algorithm, byte[] key) {
70 MessageDigestImpl h = MessageDigestImpl.create(algorithm);
71 int blockSize = blockSizeFor(algorithm);
72
73 byte[] k = key;
74 if (k.length > blockSize) {
75 h.update(k, 0, k.length);
76 k = h.digest();
77 h.reset();
78 }
79 byte[] paddedKey = new byte[blockSize];
80 System.arraycopy(k, 0, paddedKey, 0, k.length);
81
82 byte[] inner = new byte[blockSize];
83 byte[] outer = new byte[blockSize];
84 for (int i = 0; i < blockSize; i++) {
85 inner[i] = (byte) (paddedKey[i] ^ 0x36);
86 outer[i] = (byte) (paddedKey[i] ^ 0x5c);
87 }
88 return new Hmac(h, outer, inner);
89 }
90
91 private static int blockSizeFor(String algorithm) {
92 String a = MessageDigestImpl.normalise(algorithm);

Callers 10

hotpMethod · 0.95
md5Method · 0.95
sha1Method · 0.95
sha224Method · 0.95
sha256Method · 0.95
sha384Method · 0.95
sha512Method · 0.95
computeHmacMethod · 0.95
runHmacVectorsMethod · 0.95

Calls 6

createMethod · 0.95
blockSizeForMethod · 0.95
updateMethod · 0.95
digestMethod · 0.95
resetMethod · 0.95
arraycopyMethod · 0.95

Tested by 2

runHmacVectorsMethod · 0.76