Search in sources :

Example 1 with IllegalKeyException

use of com.jn.langx.security.crypto.IllegalKeyException 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 2 with IllegalKeyException

use of com.jn.langx.security.crypto.IllegalKeyException 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)2 IllegalKeyException (com.jn.langx.security.crypto.IllegalKeyException)2 BigInteger (java.math.BigInteger)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2 DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1