use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class MACUtil method calculateHmacSHA256.
@NonNull
public static byte[] calculateHmacSHA256(@NonNull byte[] message, @NonNull byte[] secret, int outputLength) {
try {
Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(secret, "HmacSHA256");
mac.init(secretKeySpec);
byte[] hmac = mac.doFinal(message);
return Arrays.copyOf(hmac, outputLength);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new UnexpectedCheckedException(e);
}
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class RSAUtil method createKeyPair.
@NonNull
public static KeyPair createKeyPair() {
KeyPairGenerator keyPairGenerator;
try {
keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4), new SecureRandom());
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
throw new UnexpectedCheckedException(e);
}
return keyPairGenerator.generateKeyPair();
}
use of com.webauthn4j.util.exception.UnexpectedCheckedException in project webauthn4j by webauthn4j.
the class TestAttestationUtil method loadECPrivateKey.
private static PrivateKey loadECPrivateKey(byte[] bytes) {
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance("EC");
return keyFactory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new UnexpectedCheckedException(e);
}
}
Aggregations