Search in sources :

Example 1 with Ecdsa

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);
}
Also used : ECPrivateKey(java.security.interfaces.ECPrivateKey) ECPublicKey(java.security.interfaces.ECPublicKey) HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint) Ecdsa(io.churchkey.ec.Ecdsa) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) Key(io.churchkey.Key) DSAPublicKey(java.security.interfaces.DSAPublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) ECPrivateKey(java.security.interfaces.ECPrivateKey) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) ECPublicKey(java.security.interfaces.ECPublicKey)

Aggregations

Key (io.churchkey.Key)1 Ecdsa (io.churchkey.ec.Ecdsa)1 BigInteger (java.math.BigInteger)1 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)1 DSAPublicKey (java.security.interfaces.DSAPublicKey)1 ECPrivateKey (java.security.interfaces.ECPrivateKey)1 ECPublicKey (java.security.interfaces.ECPublicKey)1 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 ECPoint (java.security.spec.ECPoint)1 HashMap (java.util.HashMap)1