Search in sources :

Example 1 with Rsa

use of io.churchkey.rsa.Rsa in project churchkey by tomitribe.

the class OpenSSHPrivateKey method readRsaPrivateKey.

private static Key readRsaPrivateKey(final KeyInput keyInput) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    final BigInteger modulus = keyInput.readBigInteger();
    final BigInteger publicExp = keyInput.readBigInteger();
    final BigInteger privateExp = keyInput.readBigInteger();
    final BigInteger crtCoef = keyInput.readBigInteger();
    final BigInteger primeP = keyInput.readBigInteger();
    final BigInteger primeQ = keyInput.readBigInteger();
    final String comment = keyInput.readString();
    final BigInteger one = BigInteger.valueOf(1);
    final BigInteger primeExpP = privateExp.mod(primeP.subtract(one));
    final BigInteger primeExpQ = privateExp.mod(primeQ.subtract(one));
    final Rsa.Private.Builder rsa = Rsa.Private.builder().modulus(modulus).publicExponent(publicExp).privateExponent(privateExp).crtCoefficient(crtCoef).primeP(primeP).primeQ(primeQ).primeExponentP(primeExpP).primeExponentQ(primeExpQ);
    final Rsa.Private build = rsa.build();
    final RSAPrivateCrtKey privateKey = build.toKey();
    final RSAPublicKey publicKey = build.toPublic().toKey();
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("Comment", comment);
    return new Key(privateKey, publicKey, Key.Type.PRIVATE, Key.Algorithm.RSA, Key.Format.OPENSSH, attributes);
}
Also used : Rsa(io.churchkey.rsa.Rsa) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) 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 Rsa (io.churchkey.rsa.Rsa)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 HashMap (java.util.HashMap)1