Search in sources :

Example 1 with Buffer

use of com.jn.agileway.ssh.client.utils.Buffer in project agileway by fangjinuo.

the class Eddsa25519PublicKeyCodec method encode.

@Override
public byte[] encode(PublicKey publicKey) {
    Buffer buf = new Buffer.PlainBuffer();
    EdDSAPublicKey key = (EdDSAPublicKey) publicKey;
    buf.putBytes(key.getAbyte());
    return buf.array();
}
Also used : Buffer(com.jn.agileway.ssh.client.utils.Buffer) EdDSAPublicKey(net.i2p.crypto.eddsa.EdDSAPublicKey)

Example 2 with Buffer

use of com.jn.agileway.ssh.client.utils.Buffer in project agileway by fangjinuo.

the class SshDssPublicKeyCodec method decode.

@Override
public PublicKey decode(byte[] bytes) throws CodecException {
    Buffer buf = new Buffer.PlainBuffer(bytes);
    BigInteger p, q, g, y;
    try {
        p = buf.readMPInt();
        q = buf.readMPInt();
        g = buf.readMPInt();
        y = buf.readMPInt();
    } catch (Buffer.BufferException be) {
        throw new IllegalKeyException(be);
    }
    try {
        return PKIs.getKeyFactory("DSA", null).generatePublic(new DSAPublicKeySpec(y, p, q, g));
    } catch (InvalidKeySpecException ex) {
        throw new IllegalKeyException();
    }
}
Also used : Buffer(com.jn.agileway.ssh.client.utils.Buffer) BigInteger(java.math.BigInteger) IllegalKeyException(com.jn.langx.security.crypto.IllegalKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Example 3 with Buffer

use of com.jn.agileway.ssh.client.utils.Buffer in project agileway by fangjinuo.

the class SshDssPublicKeyCodec method encode.

@Override
public byte[] encode(PublicKey publicKey) throws CodecException {
    Buffer buf = new Buffer.PlainBuffer();
    final DSAPublicKey dsaKey = (DSAPublicKey) publicKey;
    buf.putString(getName()).putMPInt(// p
    dsaKey.getParams().getP()).putMPInt(// q
    dsaKey.getParams().getQ()).putMPInt(// g
    dsaKey.getParams().getG()).putMPInt(// y
    dsaKey.getY());
    return buf.array();
}
Also used : Buffer(com.jn.agileway.ssh.client.utils.Buffer) DSAPublicKey(java.security.interfaces.DSAPublicKey)

Example 4 with Buffer

use of com.jn.agileway.ssh.client.utils.Buffer in project agileway by fangjinuo.

the class PublicKeyCodecs method decode.

public static PublicKey decode(byte[] key) {
    try {
        Buffer<?> buffer = new Buffer.PlainBuffer(key);
        final String keyType = extractKeyType(buffer);
        if (keyType == null) {
            throw new IllegalSshKeyException();
        }
        PublicKeyCodec codec = PublicKeyCodecRegistry.getInstance().get(keyType);
        if (codec == null) {
            throw new UnsupportedHostsKeyTypeException(keyType);
        }
        return codec.decode(buffer.remainingRawBytes());
    } catch (Buffer.BufferException e) {
        throw new IllegalSshKeyException(e);
    }
}
Also used : Buffer(com.jn.agileway.ssh.client.utils.Buffer) UnsupportedHostsKeyTypeException(com.jn.agileway.ssh.client.transport.hostkey.UnsupportedHostsKeyTypeException) IllegalSshKeyException(com.jn.agileway.ssh.client.transport.hostkey.IllegalSshKeyException)

Example 5 with Buffer

use of com.jn.agileway.ssh.client.utils.Buffer in project agileway by fangjinuo.

the class SshRsaPublicKeyCodec method decode.

@Override
public PublicKey decode(byte[] bytes) throws CodecException {
    Buffer<?> buf = new Buffer.PlainBuffer(bytes);
    final BigInteger e, n;
    try {
        e = buf.readMPInt();
        n = buf.readMPInt();
        return PKIs.getKeyFactory("RSA", null).generatePublic(new RSAPublicKeySpec(n, e));
    } catch (Buffer.BufferException be) {
        throw new IllegalKeyException(be);
    } catch (InvalidKeySpecException ex) {
        throw new IllegalKeyException(ex);
    }
}
Also used : Buffer(com.jn.agileway.ssh.client.utils.Buffer) BigInteger(java.math.BigInteger) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) IllegalKeyException(com.jn.langx.security.crypto.IllegalKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Aggregations

Buffer (com.jn.agileway.ssh.client.utils.Buffer)7 IllegalKeyException (com.jn.langx.security.crypto.IllegalKeyException)2 BigInteger (java.math.BigInteger)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2 SshException (com.jn.agileway.ssh.client.SshException)1 IllegalSshKeyException (com.jn.agileway.ssh.client.transport.hostkey.IllegalSshKeyException)1 UnsupportedHostsKeyTypeException (com.jn.agileway.ssh.client.transport.hostkey.UnsupportedHostsKeyTypeException)1 DSAPublicKey (java.security.interfaces.DSAPublicKey)1 DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 EdDSAPublicKey (net.i2p.crypto.eddsa.EdDSAPublicKey)1 EdDSANamedCurveSpec (net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec)1 EdDSAPublicKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec)1