JCLOUDS-617: Use the configured JCE provider in the Cipher payloads

This commit is contained in:
Ignasi Barrera 2014-07-01 15:37:50 +02:00
parent ba894fe07b
commit b9029ea7a6
3 changed files with 13 additions and 7 deletions

View File

@ -24,14 +24,18 @@ import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import org.jclouds.crypto.Crypto;
import org.jclouds.io.Payload;
public abstract class BaseCipherPayload extends DelegatingPayload {
private final Key key;
public BaseCipherPayload(Payload delegate, Key key) {
protected final Crypto crypto;
public BaseCipherPayload(Crypto crypto, Payload delegate, Key key) {
super(delegate);
this.crypto = checkNotNull(crypto, "crypto");
this.key = checkNotNull(key, "key");
}

View File

@ -23,21 +23,22 @@ import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import org.jclouds.crypto.Crypto;
import org.jclouds.io.Payload;
import com.google.common.base.Throwables;
public class RSADecryptingPayload extends BaseCipherPayload {
public RSADecryptingPayload(Payload delegate, Key key) {
super(delegate, key);
public RSADecryptingPayload(Crypto crypto, Payload delegate, Key key) {
super(crypto, delegate, key);
}
@Override
public Cipher initializeCipher(Key key) {
Cipher cipher = null;
try {
cipher = Cipher.getInstance("RSA");
cipher = crypto.cipher("RSA");
cipher.init(Cipher.DECRYPT_MODE, key);
} catch (NoSuchAlgorithmException e) {
Throwables.propagate(e);

View File

@ -23,21 +23,22 @@ import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import org.jclouds.crypto.Crypto;
import org.jclouds.io.Payload;
import com.google.common.base.Throwables;
public class RSAEncryptingPayload extends BaseCipherPayload {
public RSAEncryptingPayload(Payload delegate, Key key) {
super(delegate, key);
public RSAEncryptingPayload(Crypto crypto, Payload delegate, Key key) {
super(crypto, delegate, key);
}
@Override
public Cipher initializeCipher(Key key) {
Cipher cipher = null;
try {
cipher = Cipher.getInstance("RSA");
cipher = crypto.cipher("RSA");
cipher.init(Cipher.ENCRYPT_MODE, key);
} catch (NoSuchAlgorithmException e) {
Throwables.propagate(e);