use of org.pentaho.platform.api.util.PasswordServiceException in project pentaho-platform by pentaho.
the class PasswordServiceTest method testPasswordService.
public void testPasswordService() {
// $NON-NLS-1$
String password = "password";
IPasswordService passwordService = new KettlePasswordService();
String encryptedPassword = null;
try {
encryptedPassword = passwordService.encrypt(password);
String decryptedPassword = passwordService.decrypt(encryptedPassword);
assertEquals(password, decryptedPassword);
} catch (PasswordServiceException pse) {
// $NON-NLS-1$
fail("should not have thrown the exception");
pse.printStackTrace();
}
}
use of org.pentaho.platform.api.util.PasswordServiceException in project pentaho-platform by pentaho.
the class CipherEncryptionService method decrypt.
// From IPasswordService
@Override
public String decrypt(String encryptedPassword) throws PasswordServiceException {
try {
Cipher decCipher = Cipher.getInstance(secretKey.getAlgorithm());
decCipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
byte[] toDecryptBytes = Base64.decodeBase64(encryptedPassword.getBytes());
byte[] decryptedBytes = decCipher.doFinal(toDecryptBytes);
return new String(decryptedBytes, LocaleHelper.getSystemEncoding());
} catch (Exception ex) {
throw new PasswordServiceException(ex);
}
}
use of org.pentaho.platform.api.util.PasswordServiceException in project pentaho-platform by pentaho.
the class CipherEncryptionService method encrypt.
@Override
public String encrypt(String clearPassword) throws PasswordServiceException {
try {
Cipher encCipher = Cipher.getInstance(secretKey.getAlgorithm());
encCipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec);
byte[] toEncryptBytes = clearPassword.getBytes(LocaleHelper.getSystemEncoding());
byte[] encBytes = encCipher.doFinal(toEncryptBytes);
byte[] base64Bytes = Base64.encodeBase64(encBytes);
return new String(base64Bytes);
} catch (Exception ex) {
throw new PasswordServiceException(ex);
}
}
Aggregations