]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/crypto/PasswordBasedEncryption.java
Introduce Keyring
[lgpl/argeo-commons.git] / basic / runtime / org.argeo.basic.nodeps / src / main / java / org / argeo / util / crypto / PasswordBasedEncryption.java
index b1c18eb82a9fca0515048e8b9c96fdc22b47470c..ab36e5d8f00e02937a6cd0d396037bf846798f88 100644 (file)
@@ -41,15 +41,20 @@ public class PasswordBasedEncryption {
        private final Cipher dcipher;
 
        public PasswordBasedEncryption(char[] password) {
+               this(password, DEFAULT_SALT_8, DEFAULT_IV_16);
+       }
+
+       public PasswordBasedEncryption(char[] password, byte[] passwordSalt,
+                       byte[] initializationVector) {
                try {
                        byte[] salt = new byte[8];
-                       System.arraycopy(DEFAULT_SALT_8, 0, salt, 0, salt.length);
-                       for (int i = 0; i < password.length && i < salt.length; i++)
-                               salt[i] = (byte) password[i];
+                       System.arraycopy(passwordSalt, 0, salt, 0, salt.length);
+                       // for (int i = 0; i < password.length && i < salt.length; i++)
+                       // salt[i] = (byte) password[i];
                        byte[] iv = new byte[16];
-                       System.arraycopy(DEFAULT_IV_16, 0, iv, 0, iv.length);
-                       for (int i = 0; i < password.length && i < iv.length; i++)
-                               iv[i] = (byte) password[i];
+                       System.arraycopy(initializationVector, 0, iv, 0, iv.length);
+                       // for (int i = 0; i < password.length && i < iv.length; i++)
+                       // iv[i] = (byte) password[i];
 
                        SecretKeyFactory keyFac = SecretKeyFactory
                                        .getInstance(getSecretKeyFactoryName());