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