Skip to content

Commit 90cd5ef

Browse files
committed
Correctly convert ed25519/x25519 keys.
Signed-off-by: Markus Sabadello <markus@danubetech.com>
1 parent 2beb76b commit 90cd5ef

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/com/danubetech/keyformats/JWKToPrivateKey.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public static byte[] JWKToEd25519PrivateKeyBytes(JWK jsonWebKey) {
6161
com.nimbusds.jose.jwk.OctetKeyPair octetKeyPair = (com.nimbusds.jose.jwk.OctetKeyPair) jsonWebKey;
6262
if (! Curve.Ed25519.equals(octetKeyPair.getCurve())) throw new IllegalArgumentException("Incorrect curve: " + octetKeyPair.getCurve());
6363

64-
byte[] privateKeyBytes = octetKeyPair.getD().decode();
64+
byte[] privateKeyBytes = new byte[64];
65+
System.arraycopy(octetKeyPair.getD().decode(), 0, privateKeyBytes, 0, 32);
66+
System.arraycopy(octetKeyPair.getX().decode(), 0, privateKeyBytes, 32, 32);
6567

6668
return privateKeyBytes;
6769
}
@@ -73,7 +75,9 @@ public static byte[] JWKToX25519PrivateKeyBytes(JWK jsonWebKey) {
7375
com.nimbusds.jose.jwk.OctetKeyPair octetKeyPair = (com.nimbusds.jose.jwk.OctetKeyPair) jsonWebKey;
7476
if (! Curve.X25519.equals(octetKeyPair.getCurve())) throw new IllegalArgumentException("Incorrect curve: " + octetKeyPair.getCurve());
7577

76-
byte[] privateKeyBytes = octetKeyPair.getD().decode();
78+
byte[] privateKeyBytes = new byte[64];
79+
System.arraycopy(octetKeyPair.getD().decode(), 0, privateKeyBytes, 0, 32);
80+
System.arraycopy(octetKeyPair.getX().decode(), 0, privateKeyBytes, 32, 32);
7781

7882
return privateKeyBytes;
7983
}

0 commit comments

Comments
 (0)