From e6e4d8732d75ab521e4ea36d2d25bc6a97791500 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 24 May 2022 09:29:57 +0200 Subject: additional test --- src/main/java/org/uic/barcode/utils/ECKeyEncoder.java | 12 ++++++------ src/main/java/org/uic/barcode/utils/EllipticCurveNames.java | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/uic/barcode/utils/ECKeyEncoder.java b/src/main/java/org/uic/barcode/utils/ECKeyEncoder.java index 705b178..e1662a7 100644 --- a/src/main/java/org/uic/barcode/utils/ECKeyEncoder.java +++ b/src/main/java/org/uic/barcode/utils/ECKeyEncoder.java @@ -97,8 +97,7 @@ public class ECKeyEncoder { //we need to know the curve! String curveName = EllipticCurveNames.getInstance().getName(oid); - - //get the curve parameters + AlgorithmParameters parameters = AlgorithmParameters.getInstance(keyAlgName, provider); parameters.init(new ECGenParameterSpec(curveName)); ECParameterSpec ecParameters = parameters.getParameterSpec(ECParameterSpec.class); @@ -107,7 +106,7 @@ public class ECKeyEncoder { byte[] uncompressed = decompressPubkey(keyBytes, ecParameters); //decode the uncompressed key - return fromUncompressedPoint(uncompressed, ecParameters); + return fromUncompressedPoint(uncompressed, ecParameters, provider); } catch (Exception e) { key = null; @@ -130,7 +129,7 @@ public class ECKeyEncoder { ECParameterSpec ecParameters = parameters.getParameterSpec(ECParameterSpec.class); //decode the uncompressed key - return fromUncompressedPoint(keyBytes, ecParameters); + return fromUncompressedPoint(keyBytes, ecParameters, provider); } catch(Exception e) { //failed @@ -148,6 +147,7 @@ public class ECKeyEncoder { * * @param key the public key * @param encoding the encoding ("X509","X962_UNCOMPRESSED","X962_COMPRESSED") + * @param provider * @return the encoded key */ public static byte[] getEncoded(PublicKey key, String encoding){ @@ -206,7 +206,7 @@ public class ECKeyEncoder { * @throws Exception the exception */ private static ECPublicKey fromUncompressedPoint( - final byte[] encoded, final ECParameterSpec params) + final byte[] encoded, final ECParameterSpec params, Provider provider) throws Exception { int offset = 0; @@ -226,7 +226,7 @@ public class ECKeyEncoder { final BigInteger y = new BigInteger(1, Arrays.copyOfRange(encoded, offset, offset + keySizeBytes)); final ECPoint w = new ECPoint(x, y); final ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(w, params); - final KeyFactory keyFactory = KeyFactory.getInstance("EC"); + final KeyFactory keyFactory = KeyFactory.getInstance("EC",provider); return (ECPublicKey) keyFactory.generatePublic(ecPublicKeySpec); } diff --git a/src/main/java/org/uic/barcode/utils/EllipticCurveNames.java b/src/main/java/org/uic/barcode/utils/EllipticCurveNames.java index 41353b1..706d3c3 100644 --- a/src/main/java/org/uic/barcode/utils/EllipticCurveNames.java +++ b/src/main/java/org/uic/barcode/utils/EllipticCurveNames.java @@ -39,6 +39,7 @@ public class EllipticCurveNames { me.oitToName.put("1.3.132.0.38", "sect571k1"); me.oitToName.put("1.3.132.0.39", "sect571r1"); me.oitToName.put("1.3.132.0.10", "secp256k1"); + me.oitToName.put("1.2.840.10045.3.1.7", "secp256r1"); } return me; -- cgit v1.2.3