Added MAC function to crypto component.

This commit is contained in:
akwizgran
2016-08-26 10:06:24 +01:00
parent 00240bfa57
commit 30f2c192c6
3 changed files with 88 additions and 0 deletions

View File

@@ -403,6 +403,20 @@ class CryptoComponentImpl implements CryptoComponent {
return digest.digest();
}
@Override
public byte[] mac(SecretKey macKey, byte[]... inputs) {
Digest mac = new Blake2sDigest(macKey.getBytes());
byte[] length = new byte[INT_32_BYTES];
for (byte[] input : inputs) {
ByteUtils.writeUint32(input.length, length, 0);
mac.update(length, 0, length.length);
mac.update(input, 0, input.length);
}
byte[] output = new byte[mac.getDigestSize()];
mac.doFinal(output, 0);
return output;
}
@Override
public byte[] encryptWithPassword(byte[] input, String password) {
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();