kwin commented on code in PR #6: URL: https://github.com/apache/sling-org-apache-sling-commons-crypto/pull/6#discussion_r3637372711
########## src/main/java/org/apache/sling/commons/crypto/jca/internal/JcaPbeCryptoService.java: ########## @@ -0,0 +1,259 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.commons.crypto.jca.internal; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; +import java.security.SecureRandom; +import java.security.Security; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.InvalidParameterSpecException; +import java.security.spec.KeySpec; +import java.util.Base64; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.sling.commons.crypto.CryptoService; +import org.apache.sling.commons.crypto.PasswordProvider; +import org.apache.sling.commons.crypto.SaltProvider; +import org.jetbrains.annotations.NotNull; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Service for encrypting messages and decrypting ciphertexts using Java Crypto Architecture API. + * It relies on Password-Based key derivation function (PBKDF) for key derivation and a symmetric cipher for encryption and decryption. + * @see <a href="https://www.rfc-editor.org/info/rfc8018/#section-6.2">RFC 8018 - PBES2</a> + * + */ +@Component( + property = { + Constants.SERVICE_DESCRIPTION + "=Apache Sling Commons Crypto – JCA PBE String Crypto Service", + Constants.SERVICE_VENDOR + "=The Apache Software Foundation" + } +) +@Designate( + ocd = JcaPbeCryptoServiceConfiguration.class, + factory = true +) +@SuppressWarnings({"java:S1117", "java:S3077", "java:S6212"}) +public final class JcaPbeCryptoService implements CryptoService { + + private final PasswordProvider passwordProvider; + + private final Logger logger = LoggerFactory.getLogger(JcaPbeCryptoService.class); + + private final SecureRandom secureRandom; + private final SecretKey key; + + private final JcaPbeCryptoServiceConfiguration configuration; + + + protected static byte[] getOrCreateSalt(BundleContext bundleContext, final SaltProvider saltProvider) throws IOException { Review Comment: The Jasypt impl includes the salt in each encrypted message, which is IMHO superfluous as that is doesn't need to be changed with each encryption (in contrast to the initialization vector). @oliverlietz Do you know why this was implemented like this? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
