Bruce
Search…
Message Authentication Codes

MAC

1
Mac mac(Key key, String algorithm);
Copied!
Returns an interface for producing message authentication codes.

Usage Example

1
KeyStore keystore = keystore("classpath:/keystore.p12", "password".toCharArray(), "PKCS12");
2
Key key = secretKey(keystore, "hmac", "password".toCharArray());
3
4
Mac alice = mac(key, "HmacSHA1");
5
Mac bob = mac(key, "HmacSHA1");
6
7
byte[] message = "Hello there".getBytes(UTF_8);
8
byte[] aliceMac = alice.get(message);
9
byte[] bobMac = bob.get(message);
10
assertArrayEquals(aliceMac, bobMac);
Copied!

Encoding MAC

1
EncodingMac mac(
2
Key key,
3
String algorithm,
4
Encoding encoding,
5
Charset charset
6
);
Copied!
Returns an interface for producing encoded message authentication codes. The character set refers to the plain text message string encoding.

Usage Example

1
KeyStore keystore = keystore("classpath:/keystore.p12", "password", "PKCS12");
2
Key key = secretKey(keystore, "hmac", "password");
3
4
EncodingMac alice = mac(key, "HmacSHA1", BASE64, UTF_8);
5
EncodingMac bob = mac(key, "HmacSHA1", BASE64, UTF_8);
6
7
String message = "Hello there";
8
String aliceMac = alice.get(message);
9
String bobMac = bob.get(message);
10
assertEquals(aliceMac, bobMac);
Copied!
Last modified 6mo ago
Export as PDF
Copy link