mirror of https://github.com/apache/jclouds.git
JCLOUDS-617: Use the configured JCE provider in the Cipher payloads
This commit is contained in:
parent
ba894fe07b
commit
b9029ea7a6
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue