summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2022-05-24 09:29:57 +0200
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2022-05-24 09:29:57 +0200
commite6e4d8732d75ab521e4ea36d2d25bc6a97791500 (patch)
tree130514bbf47a979808b682c8adf50404b0434a43 /src/main/java/org/uic
parentencoding of keys different from P-256 (diff)
downloadUIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.tar
UIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.tar.gz
UIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.tar.bz2
UIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.tar.lz
UIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.tar.xz
UIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.tar.zst
UIC-barcode-e6e4d8732d75ab521e4ea36d2d25bc6a97791500.zip
Diffstat (limited to 'src/main/java/org/uic')
-rw-r--r--src/main/java/org/uic/barcode/utils/ECKeyEncoder.java12
-rw-r--r--src/main/java/org/uic/barcode/utils/EllipticCurveNames.java1
2 files changed, 7 insertions, 6 deletions
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;