@Override public AlgorithmIdentifier findEncryptionAlgorithm(AlgorithmIdentifier id) { // Use the default chooser, but replace dsaWithSha1 with dsa. This is because "dsa" is // accepted by any Android platform whereas "dsaWithSha1" is accepted only since // API Level 9. id = mDefault.findEncryptionAlgorithm(id); if (id != null) { ASN1ObjectIdentifier oid = id.getAlgorithm(); if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(oid)) { return DSA; } } return id; } }
private List<TSDMetas> extractMetas(InputStream stream) { List<TSDMetas> tsdMetasList = new ArrayList<>(); try { CMSTimeStampedData cmsTimeStampedData = new CMSTimeStampedData(stream); TimeStampToken[] tokens = cmsTimeStampedData.getTimeStampTokens(); for (int i = 0; i < tokens.length; i++) { TSDMetas tsdMetas = new TSDMetas(true, tokens[i].getTimeStampInfo().getGenTime(), tokens[i].getTimeStampInfo().getPolicy().getId(), tokens[i].getTimeStampInfo().getSerialNumber(), tokens[i].getTimeStampInfo().getTsa(), tokens[i].getTimeStampInfo().getHashAlgorithm().getAlgorithm().getId()); tsdMetasList.add(tsdMetas); } } catch (Exception ex) { LOG.error("Error in TSDParser.buildMetas {}", ex.getMessage()); tsdMetasList.clear(); } return tsdMetasList; }
private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0) throws IOException, CertificateEncodingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { TBSCertificate certificate; try (ASN1InputStream input = new ASN1InputStream(x509certificate.getTBSCertificate())) { certificate = TBSCertificate.getInstance(input.readObject()); } AlgorithmIdentifier algorithmId = certificate.getSubjectPublicKeyInfo().getAlgorithm(); IssuerAndSerialNumber serial = new IssuerAndSerialNumber( certificate.getIssuer(), certificate.getSerialNumber().getValue()); Cipher cipher; try { cipher = Cipher.getInstance(algorithmId.getAlgorithm().getId(), SecurityProvider.getProvider()); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { // should never happen, if this happens throw IOException instead throw new RuntimeException("Could not find a suitable javax.crypto provider", e); } cipher.init(1, x509certificate.getPublicKey()); DEROctetString octets = new DEROctetString(cipher.doFinal(abyte0)); RecipientIdentifier recipientId = new RecipientIdentifier(serial); return new KeyTransRecipientInfo(recipientId, algorithmId, octets); }
algorithms.put(X9ObjectIdentifiers.id_ecPublicKey, "ECDSA"); ... private KeyFactory getKeyFactory(AlgorithmIdentifier algId) throws NoSuchAlgorithmException, NoSuchProviderException { ASN1ObjectIdentifier algorithm = algId.getAlgorithm(); String algName = (String)algorithms.get(algorithm); ...
public boolean isPbmOwfPermitted(AlgorithmIdentifier pbmOwf) { ASN1ObjectIdentifier owfOid = pbmOwf.getAlgorithm(); for (ASN1ObjectIdentifier oid : owfAlgos) { if (oid.equals(owfOid)) { return true; } } return false; }
@Override public Digest getInstance(byte[] encoded) { AlgorithmIdentifier algId = AlgorithmIdentifier.getInstance(encoded); if (!algId.getAlgorithm().equals(getAlgorithmIdentifier().getAlgorithm())) { throw new IllegalArgumentException("Invalid algorithm identifier in encoded data for this digest factory: " + algId.getAlgorithm().getId()); } return getInstance(); } }
public static PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo) throws IOException { AsymmetricKeyInfoConverter converter = getAsymmetricKeyInfoConverter(publicKeyInfo.getAlgorithm().getAlgorithm()); if (converter == null) { return null; } return converter.generatePublic(publicKeyInfo); }
public static PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo) throws IOException { AsymmetricKeyInfoConverter converter = getAsymmetricKeyInfoConverter(publicKeyInfo.getAlgorithm().getAlgorithm()); if (converter == null) { return null; } return converter.generatePublic(publicKeyInfo); }
@Override public Digest getInstance(byte[] encoded) { AlgorithmIdentifier algId = AlgorithmIdentifier.getInstance(encoded); return getFactory(algId.getAlgorithm()).getInstance(); }
private XiContentSigner createRSAContentSigner(AlgorithmIdentifier signatureAlgId) throws XiSecurityException, P11TokenException { if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(signatureAlgId.getAlgorithm())) { return new P11ContentSigner.RSAPSS(cryptService, identityId, signatureAlgId, securityFactory.getRandom4Sign()); } else { return new P11ContentSigner.RSA(cryptService, identityId, signatureAlgId); } }
private void init(SubjectPublicKeyInfo keyInfo) throws IOException { XMSSMTKeyParams keyParams = XMSSMTKeyParams.getInstance(keyInfo.getAlgorithm().getParameters()); this.treeDigest = keyParams.getTreeDigest().getAlgorithm(); this.keyParams = (XMSSMTPublicKeyParameters)PublicKeyFactory.createKey(keyInfo); }
private void init(SubjectPublicKeyInfo keyInfo) throws IOException { this.treeDigest = SPHINCS256KeyParams.getInstance(keyInfo.getAlgorithm().getParameters()).getTreeDigest().getAlgorithm(); this.params = (SPHINCSPublicKeyParameters)PublicKeyFactory.createKey(keyInfo); }
public static boolean hasDHParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); return keyInfo.getAlgorithm().getAlgorithm().equals(X9ObjectIdentifiers.dhpublicnumber); }
public static boolean hasGOSTParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); return keyInfo.getAlgorithm().getAlgorithm().equals(CryptoProObjectIdentifiers.gostR3410_94); }
public static boolean isPlainECDSASigAlg(AlgorithmIdentifier algId) { ASN1ObjectIdentifier oid = Args.notNull(algId, "algId").getAlgorithm(); if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(oid)) { return true; } return false; }
private void init(PrivateKeyInfo keyInfo) throws IOException { this.attributes = keyInfo.getAttributes(); XMSSKeyParams keyParams = XMSSKeyParams.getInstance(keyInfo.getPrivateKeyAlgorithm().getParameters()); this.treeDigest = keyParams.getTreeDigest().getAlgorithm(); this.keyParams = (XMSSPrivateKeyParameters)PrivateKeyFactory.createKey(keyInfo); }
private void init(PrivateKeyInfo keyInfo) throws IOException { this.attributes = keyInfo.getAttributes(); XMSSMTKeyParams keyParams = XMSSMTKeyParams.getInstance(keyInfo.getPrivateKeyAlgorithm().getParameters()); this.treeDigest = keyParams.getTreeDigest().getAlgorithm(); this.keyParams = (XMSSMTPrivateKeyParameters)PrivateKeyFactory.createKey(keyInfo); }
public static boolean hasGost12EcParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); ASN1ObjectIdentifier alg = keyInfo.getAlgorithm().getAlgorithm(); return alg.equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256) || alg.equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512); }
protected Signer createSigner(final AlgorithmIdentifier sigAlgId, final AlgorithmIdentifier digAlgId) throws OperatorCreationException { if (!AlgorithmUtil.isDSASigAlg(sigAlgId)) { throw new OperatorCreationException( "the given algorithm is not a valid DSA signature algirthm '" + sigAlgId.getAlgorithm().getId() + "'"); } Digest dig = digestProvider.get(digAlgId); DSASigner dsaSigner = new DSASigner(); return plain ? new DSAPlainDigestSigner(dsaSigner, dig) : new DSADigestSigner(dsaSigner, dig); }
private void populateFromPubKeyInfo(SubjectPublicKeyInfo keyInfo) { if (EdECObjectIdentifiers.id_X448.equals(keyInfo.getAlgorithm().getAlgorithm())) { xdhPublicKey = new X448PublicKeyParameters(keyInfo.getPublicKeyData().getOctets(), 0); } else { xdhPublicKey = new X25519PublicKeyParameters(keyInfo.getPublicKeyData().getOctets(), 0); } }