public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm(); if (RSAUtil.isRsaOid(algOid)) { return new BCRSAPublicKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } } }
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (RSAUtil.isRsaOid(algOid)) { RSAPrivateKey rsaPrivKey = RSAPrivateKey.getInstance(keyInfo.parsePrivateKey()); if (rsaPrivKey.getCoefficient().intValue() == 0) { return new BCRSAPrivateKey(rsaPrivKey); } else { return new BCRSAPrivateCrtKey(keyInfo); } } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
private String getKeyFactoryHint(ASN1Object keyInfo) { ASN1ObjectIdentifier algId = getAlgorithmId(keyInfo); String hint = null; if (RSAUtil.isRsaOid(algId)) { hint = "RSA"; } else if (DSAUtil.isDsaOid(algId)) { hint = "DSA"; } else if (algId.equals(PKCSObjectIdentifiers.dhKeyAgreement) || algId.equals(X9ObjectIdentifiers.dhpublicnumber)) { hint = "DH"; } else if (algId.equals(OIWObjectIdentifiers.elGamalAlgorithm)) { hint = "ElGamal"; } else if (algId.equals(CryptoProObjectIdentifiers.gostR3410_94)) { hint = "GOST3410"; } if (hint == null) { throw new UnsupportedOperationException("Asymmetric key algorithm not supported: " + algId.getId()); } return hint; }
private String getKeyFactoryHint(ASN1Object keyInfo) { ASN1ObjectIdentifier algId = getAlgorithmId(keyInfo); String hint = null; if (RSAUtil.isRsaOid(algId)) { hint = "RSA"; } else if (DSAUtil.isDsaOid(algId)) { hint = "DSA"; } else if (algId.equals(PKCSObjectIdentifiers.dhKeyAgreement) || algId.equals(X9ObjectIdentifiers.dhpublicnumber)) { hint = "DH"; } else if (algId.equals(OIWObjectIdentifiers.elGamalAlgorithm)) { hint = "ElGamal"; } else if (algId.equals(CryptoProObjectIdentifiers.gostR3410_94)) { hint = "GOST3410"; } if (hint == null) { throw new UnsupportedOperationException("Asymmetric key algorithm not supported: " + algId.getId()); } return hint; }