jrihtarsic commented on code in PR #234: URL: https://github.com/apache/santuario-xml-security-java/pull/234#discussion_r1384909608
########## src/main/java/org/apache/xml/security/encryption/XMLCipherUtil.java: ########## @@ -81,4 +94,212 @@ private static AlgorithmParameterSpec constructBlockCipherParametersForGCMAlgori LOG.log(Level.DEBUG, "Successfully created GCMParameterSpec"); return gcmSpec; } + + /** + * Method buildOAEPParameters from given parameters and returns OAEPParameterSpec. If encryptionAlgorithmURI is + * not RSA_OAEP or RSA_OAEP_11, null is returned. + * + * @param encryptionAlgorithmURI the encryption algorithm URI (RSA_OAEP or RSA_OAEP_11) + * @param digestAlgorithmURI the digest algorithm URI + * @param mgfAlgorithmURI the MGF algorithm URI if encryptionAlgorithmURI is RSA_OAEP_11, otherwise parameter is ignored + * @param oaepParams the OAEP parameters bytes + * @return OAEPParameterSpec or null if encryptionAlgorithmURI is not RSA_OAEP or RSA_OAEP_11 + */ + public static OAEPParameterSpec constructOAEPParameters( + String encryptionAlgorithmURI, + String digestAlgorithmURI, + String mgfAlgorithmURI, + byte[] oaepParams + ) { + if (XMLCipher.RSA_OAEP.equals(encryptionAlgorithmURI) + || XMLCipher.RSA_OAEP_11.equals(encryptionAlgorithmURI)) { + + String jceDigestAlgorithm = "SHA-1"; + if (digestAlgorithmURI != null) { + jceDigestAlgorithm = JCEMapper.translateURItoJCEID(digestAlgorithmURI); + } + + PSource.PSpecified pSource = oaepParams == null ? + PSource.PSpecified.DEFAULT : new PSource.PSpecified(oaepParams); + + MGF1ParameterSpec mgfParameterSpec = new MGF1ParameterSpec("SHA-1"); + if (XMLCipher.RSA_OAEP_11.equals(encryptionAlgorithmURI)) { + mgfParameterSpec = constructMGF1Parameter(mgfAlgorithmURI); + } + return new OAEPParameterSpec(jceDigestAlgorithm, "MGF1", mgfParameterSpec, pSource); + } + return null; + } + + /** + * Create MGF1ParameterSpec for the given algorithm URI + * + * @param mgh1AlgorithmURI the algorithm URI. If null or empty, SHA-1 is used as default MGF1 digest algorithm. + * @return the MGF1ParameterSpec for the given algorithm URI + */ + public static MGF1ParameterSpec constructMGF1Parameter(String mgh1AlgorithmURI) { + LOG.log(Level.DEBUG, "Creating MGF1ParameterSpec for [{0}]", mgh1AlgorithmURI); Review Comment: You probably mean LOG.isLoggable(Level level), The method is useful when more data manipulation is needed to construct details to log for the level of logging. In this case (one line log) usually the logging engine handles it well. To add this to any log stement for the level (or just to debug) would just increase the complexity and reduce the readability of the code. So I would leave it as it is. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@santuario.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org