Search in sources :

Example 1 with PasswordServiceException

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();
    }
}
Also used : PasswordServiceException(org.pentaho.platform.api.util.PasswordServiceException) IPasswordService(org.pentaho.platform.api.util.IPasswordService)

Example 2 with PasswordServiceException

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);
    }
}
Also used : Cipher(javax.crypto.Cipher) PasswordServiceException(org.pentaho.platform.api.util.PasswordServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) PasswordServiceException(org.pentaho.platform.api.util.PasswordServiceException)

Example 3 with PasswordServiceException

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);
    }
}
Also used : Cipher(javax.crypto.Cipher) PasswordServiceException(org.pentaho.platform.api.util.PasswordServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) PasswordServiceException(org.pentaho.platform.api.util.PasswordServiceException)

Aggregations

PasswordServiceException (org.pentaho.platform.api.util.PasswordServiceException)3 Cipher (javax.crypto.Cipher)2 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)2 IPasswordService (org.pentaho.platform.api.util.IPasswordService)1