|
|
|
@ -60,7 +60,7 @@ public class EdECPEMResourceKeyParser extends AbstractPEMResourceKeyPairParser {
|
|
|
|
|
return Collections.singletonList(kp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static KeyPair parseEd25519KeyPair(InputStream inputStream,
|
|
|
|
|
public static KeyPair parseEd25519KeyPair(InputStream inputStream,
|
|
|
|
|
boolean okToClose) throws IOException, GeneralSecurityException {
|
|
|
|
|
try (DERParser parser = new DERParser(NoCloseInputStream.resolveInputStream(inputStream, okToClose))) {
|
|
|
|
|
return parseKeyPair(parser);
|
|
|
|
@ -118,9 +118,9 @@ public class EdECPEMResourceKeyParser extends AbstractPEMResourceKeyPairParser {
|
|
|
|
|
return decodeKeyPair(obj.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static KeyPair decodeKeyPair(byte[] keyData) throws IOException, GeneralSecurityException {
|
|
|
|
|
public static KeyPair decodeKeyPair(byte[] keyData) throws IOException, GeneralSecurityException {
|
|
|
|
|
EdECPrivateKey privateKey = getPrivateKey(keyData);
|
|
|
|
|
EdECPublicKey publicKey = getPublicKey(privateKey);
|
|
|
|
|
EdECPublicKey publicKey = getPublicKey(keyData);
|
|
|
|
|
return new KeyPair(publicKey, privateKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -142,14 +142,11 @@ public class EdECPEMResourceKeyParser extends AbstractPEMResourceKeyPairParser {
|
|
|
|
|
NamedParameterSpec spec = NamedParameterSpec.ED25519;
|
|
|
|
|
EdECPrivateKeySpec keySpec = new EdECPrivateKeySpec(spec, seed);
|
|
|
|
|
KeyFactory factory = KeyFactory.getInstance("EdDSA");
|
|
|
|
|
return EdECPrivateKey.class.cast(factory.generatePrivate(keySpec));
|
|
|
|
|
return (EdECPrivateKey) factory.generatePrivate(keySpec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static EdECPublicKey getPublicKey(PrivateKey key) throws GeneralSecurityException {
|
|
|
|
|
if (!(key instanceof EdECPrivateKey)) {
|
|
|
|
|
throw new InvalidKeyException("Private key is not EdEC private key");
|
|
|
|
|
}
|
|
|
|
|
byte[] pk = key.getEncoded();
|
|
|
|
|
private static EdECPublicKey getPublicKey(byte[] keyData) throws GeneralSecurityException {
|
|
|
|
|
byte[] pk = keyData;
|
|
|
|
|
boolean xisodd = false;
|
|
|
|
|
int lastbyteInt = pk[pk.length - 1];
|
|
|
|
|
if ((lastbyteInt & 255) >> 7 == 1) {
|
|
|
|
@ -161,6 +158,6 @@ public class EdECPEMResourceKeyParser extends AbstractPEMResourceKeyPairParser {
|
|
|
|
|
EdECPoint ep = new EdECPoint(xisodd, y);
|
|
|
|
|
EdECPublicKeySpec publicKeySpec = new EdECPublicKeySpec(paramSpec, ep);
|
|
|
|
|
KeyFactory factory = KeyFactory.getInstance("EdDSA");
|
|
|
|
|
return EdECPublicKey.class.cast(factory.generatePublic(publicKeySpec));
|
|
|
|
|
return (EdECPublicKey) factory.generatePublic(publicKeySpec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|