/** * For given encryption algorithm & digest algorithm this function returns the signature algorithm. * * @param encryptionAlgorithm * @param digestAlgorithm * @return */ public static SignatureAlgorithm getAlgorithm(final EncryptionAlgorithm encryptionAlgorithm, final DigestAlgorithm digestAlgorithm) { String digestAlgorithm_ = digestAlgorithm.getName(); digestAlgorithm_ = digestAlgorithm_.replace("-", ""); final String javaName = digestAlgorithm_ + "with" + encryptionAlgorithm.getName(); return JAVA_ALGORITHMS.get(javaName); }
@Override public EncryptionAlgorithm getEncryptionAlgorithm() throws DSSException { if (privateKey instanceof RSAPrivateKey) { return EncryptionAlgorithm.RSA; } else if (privateKey instanceof DSAPrivateKey) { return EncryptionAlgorithm.DSA; } else if (privateKey instanceof ECPrivateKey) { return EncryptionAlgorithm.ECDSA; } else if (EncryptionAlgorithm.RSA.getName().equals(privateKey.getAlgorithm())) { return EncryptionAlgorithm.RSA; } else if (EncryptionAlgorithm.DSA.getName().equals(privateKey.getAlgorithm())) { return EncryptionAlgorithm.DSA; } else if (EncryptionAlgorithm.ECDSA.getName().equals(privateKey.getAlgorithm())) { return EncryptionAlgorithm.ECDSA; } else { throw new DSSException("Don't find algorithm for PrivateKey of type " + privateKey.getClass()); } } }
/** * This method returns the public algorithm extracted from public key infrastructure. (ex: RSA) * * @param publicKey * @return */ public static String getPublicKeyEncryptionAlgo(final Key publicKey) { String publicKeyAlgorithm = "?"; // (List of different public key implementations with instanceOf test removed) publicKeyAlgorithm = publicKey.getAlgorithm(); if (!"?".equals(publicKeyAlgorithm)) { try { publicKeyAlgorithm = EncryptionAlgorithm.forName(publicKeyAlgorithm).getName(); } catch (DSSException e) { LOG.error(e.getMessage()); } } return publicKeyAlgorithm; }
final SignatureAlgorithm revocationSignatureAlgo = revocationToken.getSignatureAlgorithm(); final boolean unknownAlgorithm = revocationSignatureAlgo == null; final String encryptionAlgorithmName = unknownAlgorithm ? "?" : revocationSignatureAlgo.getEncryptionAlgorithm().getName(); xmlBasicSignatureType.setEncryptionAlgoUsedToSignThisToken(encryptionAlgorithmName); final String keyLength = revocationToken.getKeyLength();
xmlBasicSignatureType.setEncryptionAlgoUsedToSignThisToken(signatureAlgorithm.getEncryptionAlgorithm().getName()); final String keyLength = certToken.getKeyLength(); xmlBasicSignatureType.setKeyLengthUsedToSignThisToken(keyLength);
final String encryptionAlgorithmString = encryptionAlgorithm == null ? "?" : encryptionAlgorithm.getName(); xmlBasicSignature.setEncryptionAlgoUsedToSignThisToken(encryptionAlgorithmString);
if (signatureAlgorithm != null) { xmlBasicSignatureType.setEncryptionAlgoUsedToSignThisToken(signatureAlgorithm.getEncryptionAlgorithm().getName()); xmlBasicSignatureType.setDigestAlgoUsedToSignThisToken(signatureAlgorithm.getDigestAlgorithm().getName());