@@ -17,7 +17,7 @@ Licensed to the Apache Software Foundation (ASF) under one
17
17
under the License.
18
18
*/
19
19
20
- package org .sonatype .plexus .components .cipher ;
20
+ package org .codehaus .plexus .components .cipher . internal ;
21
21
22
22
import javax .crypto .Cipher ;
23
23
import javax .crypto .NoSuchPaddingException ;
@@ -26,6 +26,8 @@ Licensed to the Apache Software Foundation (ASF) under one
26
26
import javax .crypto .spec .PBEKeySpec ;
27
27
import javax .crypto .spec .SecretKeySpec ;
28
28
29
+ import java .nio .charset .Charset ;
30
+ import java .nio .charset .StandardCharsets ;
29
31
import java .security .InvalidAlgorithmParameterException ;
30
32
import java .security .InvalidKeyException ;
31
33
import java .security .NoSuchAlgorithmException ;
@@ -34,30 +36,21 @@ Licensed to the Apache Software Foundation (ASF) under one
34
36
import java .security .spec .KeySpec ;
35
37
import java .util .Base64 ;
36
38
39
+ import org .codehaus .plexus .components .cipher .PlexusCipherException ;
40
+
37
41
/**
38
42
* This class is thread-safe.
39
43
*
40
44
* @author Oleg Gusakov
41
45
*/
42
46
public class PBECipher {
43
- protected static final String STRING_ENCODING = "UTF8" ;
44
-
47
+ protected static final Charset STRING_ENCODING = StandardCharsets .UTF_8 ;
45
48
protected static final int SPICE_SIZE = 16 ;
46
-
47
49
protected static final int SALT_SIZE = 8 ;
48
-
49
50
protected static final int CHUNK_SIZE = 16 ;
50
-
51
- protected static final byte WIPER = 0 ;
52
-
53
- protected static final String DIGEST_ALG = "SHA-256" ;
54
-
55
51
protected static final String KEY_ALG = "AES" ;
56
-
57
52
protected static final String CIPHER_ALG = "AES/CBC/PKCS5Padding" ;
58
-
59
53
protected static final int PBE_ITERATIONS = 310000 ;
60
-
61
54
private static final SecureRandom _secureRandom = new SecureRandom ();
62
55
63
56
// ---------------------------------------------------------------
@@ -95,7 +88,7 @@ public String encrypt64(final String clearText, final String password) throws Pl
95
88
96
89
return Base64 .getEncoder ().encodeToString (allEncryptedBytes );
97
90
} catch (Exception e ) {
98
- throw new PlexusCipherException (e );
91
+ throw new PlexusCipherException (e . getMessage (), e );
99
92
}
100
93
}
101
94
@@ -122,7 +115,7 @@ public String decrypt64(final String encryptedText, final String password) throw
122
115
123
116
return new String (clearBytes , STRING_ENCODING );
124
117
} catch (Exception e ) {
125
- throw new PlexusCipherException (e );
118
+ throw new PlexusCipherException (e . getMessage (), e );
126
119
}
127
120
}
128
121
// -------------------------------------------------------------------------------
@@ -131,7 +124,7 @@ private Cipher createCipher(final char[] pwd, byte[] salt, final int mode)
131
124
InvalidAlgorithmParameterException , InvalidKeySpecException {
132
125
133
126
KeySpec spec = new PBEKeySpec (pwd , salt , PBE_ITERATIONS , SPICE_SIZE * 16 );
134
- SecretKeyFactory factory = SecretKeyFactory .getInstance ("PBKDF2WithHmacSHA1 " );
127
+ SecretKeyFactory factory = SecretKeyFactory .getInstance ("PBKDF2WithHmacSHA512 " );
135
128
byte [] keyAndIv = factory .generateSecret (spec ).getEncoded ();
136
129
137
130
byte [] key = new byte [SPICE_SIZE ];
0 commit comments