Bruce
  • Welcome
  • Essentials
    • Features
    • Getting Started
    • General Concepts
    • Roadmap
  • API
    • Cheat Sheet
    • Key Stores
    • Certificates
    • Keys
    • Digests
    • Signatures
    • Verification
    • Symmetric Ciphers
    • Asymmetric Ciphers
    • Message Authentication Codes
Powered by GitBook
On this page
  • MAC
  • Usage Example
  • Encoding MAC
  • Usage Example

Was this helpful?

Export as PDF
  1. API

Message Authentication Codes

MAC

Mac mac(Key key, String algorithm);

Returns an interface for producing message authentication codes.

Usage Example

KeyStore keystore = keystore("classpath:/keystore.p12", "password".toCharArray(), "PKCS12");
Key key = secretKey(keystore, "hmac", "password".toCharArray());

Mac alice = mac(key, "HmacSHA1");
Mac bob = mac(key, "HmacSHA1");

byte[] message = "Hello there".getBytes(UTF_8);
byte[] aliceMac = alice.get(message);
byte[] bobMac = bob.get(message);
assertArrayEquals(aliceMac, bobMac);

Encoding MAC

EncodingMac mac(
    Key key, 
    String algorithm, 
    Encoding encoding, 
    Charset charset
);

Returns an interface for producing encoded message authentication codes. The character set refers to the plain text message string encoding.

Usage Example

KeyStore keystore = keystore("classpath:/keystore.p12", "password", "PKCS12");
Key key = secretKey(keystore, "hmac", "password");

EncodingMac alice = mac(key, "HmacSHA1", BASE64, UTF_8);
EncodingMac bob = mac(key, "HmacSHA1", BASE64, UTF_8);

String message = "Hello there";
String aliceMac = alice.get(message);
String bobMac = bob.get(message);
assertEquals(aliceMac, bobMac);
PreviousAsymmetric Ciphers

Last updated 3 years ago

Was this helpful?