< prev index next >

src/java.base/share/classes/sun/security/x509/AlgorithmId.java

Print this page
rev 12345 : 8056174: New APIs for jar signing

*** 975,980 **** --- 975,1006 ---- if (with > 0) { return signatureAlgorithm.substring(0, with); } return null; } + + // Both arg cannot be null + public static void checkKeyAndSigAlgMatch(String keyAlgorithm, String signatureAlgorithm) { + String sigAlgUpperCase = signatureAlgorithm.toUpperCase(Locale.US); + if ((sigAlgUpperCase.endsWith("WITHRSA") && + !keyAlgorithm.equalsIgnoreCase("RSA")) || + (sigAlgUpperCase.endsWith("WITHECDSA") && + !keyAlgorithm.equalsIgnoreCase("EC")) || + (sigAlgUpperCase.endsWith("WITHDSA") && + !keyAlgorithm.equalsIgnoreCase("DSA"))) { + throw new IllegalArgumentException( + "key algorithm not compatible with signature algorithm"); + } + } + + // Arg cannot be null, might return null + public static String getDefaultSigAlgForKeyAlg(String keyAlgorithm) { + if (keyAlgorithm.equalsIgnoreCase("DSA")) + return "SHA256withDSA"; + else if (keyAlgorithm.equalsIgnoreCase("RSA")) + return "SHA256withRSA"; + else if (keyAlgorithm.equalsIgnoreCase("EC")) + return "SHA256withECDSA"; + else + return null; + } }
< prev index next >