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();
}
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();
}
}
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();
}
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);
}
}
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);
}
}
Aggregations