use of java.security.KeyException in project scheduling by ow2-proactive.
the class KeyPairUtil method decrypt.
/**
* Decrypt a message using asymmetric keys
*
* @param privKey Private key used for decryption
* @param cipherParams cipher parameters: transformations (ie RSA/ECB/NoPadding)
* @param message the encrypted message
* @return the decrypted message
* @throws KeyException private key recovery failed, decryption failed
*/
public static synchronized byte[] decrypt(PrivateKey privKey, String cipherParams, byte[] message) throws KeyException {
Cipher ciph = null;
try {
ciph = Cipher.getInstance(cipherParams);
ciph.init(Cipher.DECRYPT_MODE, privKey, KeyUtil.getSecureRandom());
} catch (Exception e) {
throw new KeyException("Could not initialize cipher", e);
}
byte[] res = null;
try {
res = ciph.doFinal(message);
} catch (Exception e) {
throw new KeyException("Could not descrypt message.", e);
}
return res;
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class KeyUtil method encrypt.
/**
* Encrypt a message using a symmetric key
*
* @param key secret key used for encryption
* @param cipherParams cipher parameters: transformations, ie AES
* @param message the message to encrypt
* @return the encrypted message
* @throws KeyException encryption failed, public key recovery failed
*/
public static synchronized byte[] encrypt(SecretKey key, String cipherParams, byte[] message) throws KeyException {
Cipher ciph = null;
try {
ciph = Cipher.getInstance(cipherParams);
ciph.init(Cipher.ENCRYPT_MODE, key, getSecureRandom());
} catch (Exception e) {
throw new KeyException("Coult not initialize cipher", e);
}
byte[] res = null;
try {
res = ciph.doFinal(message);
} catch (Exception e) {
throw new KeyException("Could not encrypt message", e);
}
return res;
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class SmartProxyImpl method init.
@Override
public void init(ConnectionInfo connectionInfo) throws SchedulerException, LoginException {
this.connectionInfo = connectionInfo;
if (connectionInfo.getCredentialFile() != null) {
try {
Credentials credentials = Credentials.getCredentials(connectionInfo.getCredentialFile().getAbsolutePath());
init(connectionInfo.getUrl(), credentials);
} catch (KeyException e) {
throw new LoginException(e.getMessage());
}
} else {
CredData cred = new CredData(CredData.parseLogin(connectionInfo.getLogin()), CredData.parseDomain(connectionInfo.getLogin()), connectionInfo.getPassword());
init(connectionInfo.getUrl(), cred);
}
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class SchedulingService method addThirdPartyCredentials.
/**
* Create a new Credential object containing users' 3rd Party Credentials.
*
* @param creds credentials for specific user
* @return in case of success new object containing the 3rd party credentials used to create bindings
* at clean script
*/
Credentials addThirdPartyCredentials(Credentials creds) throws KeyException, IllegalAccessException {
// retrieve scheduler key pair
String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
String publicKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PUBKEY_PATH.getValueAsString());
// get keys from task
PrivateKey privateKey = Credentials.getPrivateKey(privateKeyPath);
PublicKey publicKey = Credentials.getPublicKey(publicKeyPath);
// retrieve the current creData from task
CredData credData = creds.decrypt(privateKey);
// retrive database to get third party credentials from
SchedulerDBManager dbManager = getInfrastructure().getDBManager();
if (dbManager != null) {
Map<String, HybridEncryptedData> thirdPartyCredentials = dbManager.thirdPartyCredentialsMap(credData.getLogin());
if (thirdPartyCredentials == null) {
logger.error("Failed to retrieve Third Party Credentials!");
throw new KeyException("Failed to retrieve thirdPartyCredentials!");
} else {
// cycle third party credentials, add one-by-one to the decrypter
for (Map.Entry<String, HybridEncryptedData> thirdPartyCredential : thirdPartyCredentials.entrySet()) {
String decryptedValue = HybridEncryptionUtil.decryptString(thirdPartyCredential.getValue(), privateKey);
credData.addThirdPartyCredential(thirdPartyCredential.getKey(), decryptedValue);
}
}
}
return Credentials.createCredentials(credData, publicKey);
}
Aggregations