Search in sources :

Example 16 with UnexpectedCheckedException

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);
    }
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) Mac(javax.crypto.Mac) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 17 with UnexpectedCheckedException

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();
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 18 with UnexpectedCheckedException

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);
    }
}
Also used : UnexpectedCheckedException(com.webauthn4j.util.exception.UnexpectedCheckedException) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyFactory(java.security.KeyFactory)

Aggregations

UnexpectedCheckedException (com.webauthn4j.util.exception.UnexpectedCheckedException)18 NonNull (org.checkerframework.checker.nullness.qual.NonNull)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 InvalidKeyException (java.security.InvalidKeyException)4 SecretKeySpec (javax.crypto.spec.SecretKeySpec)4 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 CertificateException (java.security.cert.CertificateException)3 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)3 ContentSigner (org.bouncycastle.operator.ContentSigner)3 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)3 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)3 CertFileTrustAnchorsProvider (com.webauthn4j.anchor.CertFileTrustAnchorsProvider)2 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 Certificate (java.security.cert.Certificate)2 BadPaddingException (javax.crypto.BadPaddingException)2 Cipher (javax.crypto.Cipher)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 Mac (javax.crypto.Mac)2