MCPcopy Create free account
hub / github.com/M66B/FairEmail / HMAC

Method HMAC

app/src/main/java/eu/faircode/email/Helper.java:3823–3856  ·  view source on GitHub ↗
(String algo, int blocksize, byte[] key, byte[] text)

Source from the content-addressed store, hash-verified

3821 }
3822
3823 public static String HMAC(String algo, int blocksize, byte[] key, byte[] text) throws NoSuchAlgorithmException {
3824 MessageDigest md = MessageDigest.getInstance(algo);
3825
3826 if (key.length > blocksize)
3827 key = md.digest(key);
3828
3829 byte[] ipad = new byte[blocksize];
3830 byte[] opad = new byte[blocksize];
3831
3832 for (int i = 0; i < key.length; i++) {
3833 ipad[i] = key[i];
3834 opad[i] = key[i];
3835 }
3836
3837 for (int i = 0; i < blocksize; i++) {
3838 ipad[i] ^= 0x36;
3839 opad[i] ^= 0x5c;
3840 }
3841
3842 byte[] digest;
3843
3844 md.update(ipad);
3845 md.update(text);
3846 digest = md.digest();
3847
3848 md.update(opad);
3849 md.update(digest);
3850 digest = md.digest();
3851
3852 StringBuilder sb = new StringBuilder();
3853 for (byte b : digest)
3854 sb.append(String.format("%02x", b));
3855 return sb.toString();
3856 }
3857
3858 // Miscellaneous
3859

Callers 2

authenticateMethod · 0.95
authenticateMethod · 0.95

Calls 6

digestMethod · 0.65
getInstanceMethod · 0.45
updateMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected