Merge branch '364-add-mac-to-crypto-component' into 'master'

Add MAC function to crypto component



See merge request !295
This commit is contained in:
Torsten Grote
2016-08-26 13:34:56 +00:00
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();