use of com.bluenimble.platform.crypto.Base64 in project serverless by bluenimble.
the class SimpleSigner method signWithKey.
private void signWithKey(SecureDocument doc, SecretKey key) throws SignerException {
try {
byte[] signature = null;
if (key.getAlgorithm().equals(Algorithm.HmacSHA1.getId())) {
Mac mac = Mac.getInstance(key.getAlgorithm());
mac.init(key);
signature = doc.getBytes();
if (SignatureAware.class.isAssignableFrom(doc.getClass())) {
((SignatureAware) doc).setSignature(new Base64().encode(mac.doFinal(signature)));
} else {
doc.setBytes(mac.doFinal(signature));
}
} else {
MessageDigest md = MessageDigest.getInstance(key.getAlgorithm());
signature = md.digest(doc.getBytes());
if (SignatureAware.class.isAssignableFrom(doc.getClass())) {
((SignatureAware) doc).setSignature(hexEncode(signature));
} else {
doc.setBytes(hexEncode(signature));
}
}
} catch (Throwable th) {
throw new SignerException(th, th.getMessage());
}
}
Aggregations