@Override public AlgorithmIdentifier getAlgorithmIdentifier() { return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1); }
/** * Returns a {@link PEMKeyPair} object with direct access to the public and private keys given a PKCS #8 private key. * * @param privateKeyInfo the PKCS #8 private key info * @return the PKCS #1 public and private key pair * @throws IOException if there is an error converting the key pair */ private static PEMKeyPair convertPrivateKeyFromPKCS8ToPKCS1(PrivateKeyInfo privateKeyInfo) throws IOException { // Parse the key wrapping to determine the internal key structure ASN1Encodable asn1PrivateKey = privateKeyInfo.parsePrivateKey(); // Convert the parsed key to an RSA private key RSAPrivateKey keyStruct = RSAPrivateKey.getInstance(asn1PrivateKey); // Create the RSA public key from the modulus and exponent RSAPublicKey pubSpec = new RSAPublicKey( keyStruct.getModulus(), keyStruct.getPublicExponent()); // Create an algorithm identifier for forming the key pair AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); if (isVerbose()) { logger.info("Converted private key from PKCS #8 to PKCS #1 RSA private key"); } // Create the key pair container return new PEMKeyPair(new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct)); }
DERSet set = new DERSet(new RecipientInfo(recipientInfo)); AlgorithmIdentifier algorithmId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(algorithm), object); EncryptedContentInfo encryptedInfo = new EncryptedContentInfo(PKCSObjectIdentifiers.data, algorithmId, new DEROctetString(bytes));
public RSAKeypairGenControl(int keysize, BigInteger publicExponent, ASN1ObjectIdentifier keyAlgorithmOid) { if (keysize < 1024 || keysize % 512 != 0) { throw new IllegalArgumentException("invalid keysize " + keysize); } this.keysize = keysize; this.publicExponent = (publicExponent != null) ? publicExponent : BigInteger.valueOf(0x10001); this.keyAlgorithm = new AlgorithmIdentifier( (keyAlgorithmOid != null) ? keyAlgorithmOid : PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); }
private static AlgorithmIdentifier getDSASigAlgId(HashAlgo hashAlgo) throws NoSuchAlgorithmException { Args.notNull(hashAlgo, "hashAlgo"); ASN1ObjectIdentifier sigAlgOid = digestToDSASigAlgMap.get(hashAlgo); if (sigAlgOid == null) { throw new NoSuchAlgorithmException("unsupported hash " + hashAlgo + " for DSA key"); } return new AlgorithmIdentifier(sigAlgOid); } // method getDSASigAlgId
public static AlgorithmIdentifier buildRSAPSSAlgId(final HashAlgoType digestAlg) throws NoSuchAlgorithmException { RSASSAPSSparams params = createPSSRSAParams(digestAlg); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSASSA_PSS, params); }
@Override public AlgorithmIdentifier getAlgorithmIdentifier() { GCMParameters params = new GCMParameters(nonce, tagByteLen); return new AlgorithmIdentifier(oid, params); }
public ECKeypairGenControl(ASN1ObjectIdentifier curveOid, ASN1ObjectIdentifier keyAlgorithmOid) { this.curveOid = Args.notNull(curveOid, "curveOid"); this.keyAlgorithm = new AlgorithmIdentifier( (keyAlgorithmOid != null) ? keyAlgorithmOid : X9ObjectIdentifiers.id_ecPublicKey, curveOid); }
public AlgorithmIdentifier getHashAlgorithm() { if (null == this.otherHash) { return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1); } return this.otherHash.getHashAlgorithm(); }
public static AlgorithmIdentifier getMacAlgId(String macAlgName) throws NoSuchAlgorithmException { String algoS = Args.notNull(macAlgName, "macAlgName").toUpperCase(); algoS = canonicalizeAlgoText(algoS); ASN1ObjectIdentifier oid = macAlgNameToOidMap.get(algoS); if (oid == null) { throw new NoSuchAlgorithmException("unsupported MAC algorithm " + algoS); } return new AlgorithmIdentifier(oid, DERNull.INSTANCE); } // method getMacAlgId
private static AlgorithmIdentifier getRSASigAlgId(HashAlgo hashAlgo, boolean mgf1) throws NoSuchAlgorithmException { Args.notNull(hashAlgo, "hashAlgo"); if (mgf1) { return buildRSAPSSAlgId(hashAlgo); } ASN1ObjectIdentifier sigAlgOid = digestToRSASigAlgMap.get(hashAlgo); if (sigAlgOid == null) { throw new NoSuchAlgorithmException("unsupported hash " + hashAlgo + " for RSA key"); } return new AlgorithmIdentifier(sigAlgOid, DERNull.INSTANCE); } // method getRSASigAlgId
private AlgorithmIdentifier determineKeyEncryptionAlgorithmIdentifier(String keyEncryptionAlgorithm, TransRecipientInfo keyTransRecipient) throws CryptoCmsException { if (keyEncryptionAlgorithm == null) { throw new CryptoCmsException("Key encryption algorithm of recipient info '" + keyTransRecipient + "' is missing"); } if ("RSA".equals(keyEncryptionAlgorithm)) { return new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption); } throw new CryptoCmsException("Key encryption algorithm '" + keyEncryptionAlgorithm + "' of recipient info '" + keyTransRecipient + "' is not supported"); } }
private KeyPairWithSubjectPublicKeyInfo genRSAKeypair(final int keysize, final BigInteger publicExponent, final SecureRandom random) throws Exception { KeyPair kp = KeyUtil.generateRSAKeypair(keysize, publicExponent, random); java.security.interfaces.RSAPublicKey rsaPubKey = (java.security.interfaces.RSAPublicKey) kp.getPublic(); SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo( new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(rsaPubKey.getModulus(), rsaPubKey.getPublicExponent())); return new KeyPairWithSubjectPublicKeyInfo(kp, spki); }
private static RSASSAPSSparams createPSSRSAParams(HashAlgo digestAlg) throws NoSuchAlgorithmException { int saltSize = Args.notNull(digestAlg, "digestAlg").getLength(); AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlg.getOid(), DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); } // method createPSSRSAParams
private HashAlgo(int length, AlgorithmCode algorithmCode, String oid, String name) { this.length = length; this.algorithmCode = algorithmCode; this.oid = new ASN1ObjectIdentifier(oid).intern(); this.algId = new AlgorithmIdentifier(this.oid, DERNull.INSTANCE); this.name = name; try { this.encoded = new ASN1ObjectIdentifier(oid).getEncoded(); } catch (IOException ex) { throw new IllegalArgumentException("invalid oid: " + oid); } }
public DSAKeypairGenControl(BigInteger p, BigInteger q, BigInteger g, ASN1ObjectIdentifier keyAlgorithmOid) { this.parameterSpec = new DSAParameterSpec(p, q, g); this.keyAlgorithm = new AlgorithmIdentifier( (keyAlgorithmOid != null) ? keyAlgorithmOid : X9ObjectIdentifiers.id_dsa, new DSAParameter(p, q, g)); }
static CertificateID generateCertificateId(X509Certificate issuerCert, BigInteger serialNumber, ASN1ObjectIdentifier identifier) throws OperatorCreationException, CertificateEncodingException, OCSPException { return new CertificateID( new JcaDigestCalculatorProviderBuilder().build().get(new AlgorithmIdentifier(identifier, DERNull.INSTANCE)), new JcaX509CertificateHolder(issuerCert), serialNumber); }
static CertificateID generateCertificateId(X509Certificate issuerCert, BigInteger serialNumber, ASN1ObjectIdentifier identifier) throws OperatorCreationException, CertificateEncodingException, OCSPException { return new CertificateID( new JcaDigestCalculatorProviderBuilder().build().get(new AlgorithmIdentifier(identifier, DERNull.INSTANCE)), new JcaX509CertificateHolder(issuerCert), serialNumber); }
/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. */ public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(elSpec.getP(), elSpec.getG())), new ASN1Integer(getX())); }
/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. */ public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient())); }