@@ -20,11 +20,7 @@ public class EncryptDecryptHandler {
2020 * @return an encrypted String
2121 */
2222 public String encrypt ( String value ) {
23-
24- BasicTextEncryptor textEncryptor = new BasicTextEncryptor ();
25- textEncryptor .setPassword (AppAuthenticator .getInstance ().getAppAuthInfo ().getSharedSecret ());
26-
27- return textEncryptor .encrypt (value );
23+ return encrypt (null , value );
2824 }
2925
3026 /**
@@ -34,9 +30,17 @@ public String encrypt( String value) {
3430 * @return an encrypted string.
3531 */
3632 public String encrypt (String key , String value ) {
33+ if (value ==null ) {
34+ throw new IllegalArgumentException ("String to be encrypted required" );
35+ }
3736
3837 BasicTextEncryptor textEncryptor = new BasicTextEncryptor ();
39- textEncryptor .setPassword (AppAuthenticator .getInstance ().getAppAuthInfo ().getSharedSecret ()+key );
38+
39+ String sharedSecret = AppAuthenticator .getInstance ().getAppAuthInfo ().getSharedSecret ();
40+ if (sharedSecret ==null && key ==null ) {
41+ throw new IllegalArgumentException ("Password key required" );
42+ }
43+ textEncryptor .setPassword (sharedSecret +key );
4044
4145 return textEncryptor .encrypt (value );
4246 }
@@ -47,11 +51,7 @@ public String encrypt(String key, String value) {
4751 * @return the decrypted
4852 */
4953 public String decrypt ( String encryptedStr ) {
50-
51- BasicTextEncryptor textEncryptor = new BasicTextEncryptor ();
52- textEncryptor .setPassword (AppAuthenticator .getInstance ().getAppAuthInfo ().getSharedSecret ());
53-
54- return textEncryptor .decrypt (encryptedStr );
54+ return decrypt (null , encryptedStr );
5555 }
5656
5757 /**
@@ -61,6 +61,9 @@ public String decrypt( String encryptedStr) {
6161 * @return a string in clear text.
6262 */
6363 public String decrypt (String key , String encryptedStr ) {
64+ if (encryptedStr ==null ) {
65+ throw new IllegalArgumentException ("String to be decrypted required" );
66+ }
6467
6568 BasicTextEncryptor textEncryptor = new BasicTextEncryptor ();
6669 textEncryptor .setPassword (AppAuthenticator .getInstance ().getAppAuthInfo ().getSharedSecret ()+key );
0 commit comments