use of io.churchkey.ec.Ecdsa in project churchkey by tomitribe.
the class OpenSSHPrivateKey method readEcdsaPrivateKey.
private static Key readEcdsaPrivateKey(final Curve curve, final KeyInput keyInput) throws IOException {
final String curveName = keyInput.readString();
if (!curve.name().equals(curveName)) {
throw new IllegalStateException(String.format("Mismatched curve %s does not match key type of ecdsa-sha2-%s", curveName, curve.name()));
}
final byte[] q = keyInput.readBytes();
final ECPoint ecPoint = EcPoints.fromBytes(q);
final BigInteger d = new BigInteger(1, keyInput.readBytes());
final Ecdsa.Private build = Ecdsa.Private.builder().curveName(curveName).d(d).x(ecPoint.getAffineX()).y(ecPoint.getAffineY()).build();
final ECPrivateKey ecPrivateKey = build.toKey();
final ECPublicKey publicKey = build.toPublic().toKey();
final Map<String, String> attributes = new HashMap<String, String>();
final String comment = keyInput.readString();
if (comment != null) {
attributes.put("Comment", comment);
} else {
attributes.put("Comment", "");
}
return new Key(ecPrivateKey, publicKey, Key.Type.PRIVATE, Key.Algorithm.EC, Key.Format.OPENSSH, attributes);
}
Aggregations