public class EncryptedValue
extends java.lang.Object
implements oracle.security.crypto.asn1.ASN1Object
| Constructor and Description |
|---|
EncryptedValue()
Create new, empty
EncryptedValue. |
EncryptedValue(byte[] encValue)
Create a new
EncryptedValue with the specified encypted value |
EncryptedValue(java.io.InputStream is) |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decrypt(EncryptedValue encVal, java.security.PrivateKey recipKey)
Decrypt an
EncryptedValue and return the bytes of the value. |
static EncryptedValue |
encrypt(oracle.security.crypto.asn1.ASN1Object obj, javax.crypto.SecretKey encrKey, java.security.PublicKey recipKey)
Creates a new
EncryptedValue instance whose value is the DER encoding of the given ASN1Object. |
byte[] |
getEncSymmKey()
Returns the encrypted symmetric key used to encrypt the value.
|
byte[] |
getEncValue()
Returns the encrypted value of this object.
|
oracle.security.crypto.core.AlgorithmIdentifier |
getIntendedAlg()
Returns the intended algorithm of the encrypted value.
|
oracle.security.crypto.core.AlgorithmIdentifier |
getKeyAlg()
Returns the algorithm used to encrypt the symmetric key.
|
oracle.security.crypto.core.AlgorithmIdentifier |
getSymmAlg()
Returns the symmetric algorithm used to encrypt the value.
|
byte[] |
getValueHint()
Returns the value hint of the encrypted value.
|
void |
input(java.io.InputStream is) |
int |
length() |
void |
output(java.io.OutputStream os) |
void |
setEncSymmKey(byte[] encSymmKey)
Sets the encrypted symmetric key used to encrypt the value.
|
void |
setIntendedAlg(oracle.security.crypto.core.AlgorithmIdentifier intendedAlg)
Sets the intended algorithm for the encrypted value.
|
void |
setKeyAlg(oracle.security.crypto.core.AlgorithmIdentifier keyAlg)
Sets the algorithm used to encrypt the symmetric key.
|
void |
setSymmAlg(oracle.security.crypto.core.AlgorithmIdentifier symmAlg)
Sets the symmetric algorithm used to encrypt the value.
|
void |
setValueHint(byte[] valueHint)
Sets the value hint for the encrypted value.
|
java.lang.String |
toString() |
public EncryptedValue()
EncryptedValue. Note that an instance created using this constructor is not valid, and is intended primarily for use in conjunction with the input(java.io.InputStream) method.public EncryptedValue(byte[] encValue)
EncryptedValue with the specified encypted value
public EncryptedValue(java.io.InputStream is)
throws java.io.IOException
java.io.IOExceptionpublic static EncryptedValue encrypt(oracle.security.crypto.asn1.ASN1Object obj, javax.crypto.SecretKey encrKey, java.security.PublicKey recipKey) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException, java.security.InvalidKeyException
EncryptedValue instance whose value is the DER encoding of the given ASN1Object.
For example, to encrypt a certificate:
// The certificate to be encrypted.
X509 cert = ... ;
// The public key of the recipient.
PublicKey pubKey = ... ;
// Generate a random triple-DES encryption key.
SymmetricKeyGenerator keyGen =
SymmetricKeyGenerator.getInstance(AlgID.DES_EDE3_CBC);
SymmetricKey symmKey = keyGen.generateKey();
// Create the EncryptedValue.
EncryptedValue encCert = EncryptedValue.encrypt(cert, symmKey, pubKey);
Note the changes in the method signature
Previously public static EncryptedValue encrypt (ASN1Object , SymmetricKey ,oracle.security.crypto.core.PublicKey)
Now public static EncryptedValue encrypt (ASN1Object , SecretKey ,java.security.PublicKey)
Note the change in the exceptions declared to be thrown.
Exceptions no longer thrown -- AlgorithmIdentifierException,CipherException
Exceptions introduced -- java.security.InvalidKeyException ,NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException,BadPaddingException
obj - The ASN1Object to be encrypted.encrKey - The symmetric key that will be used to encrypt the object. Must have a valid algorithm identifer.recipKey - The public key that will be used to encrypt the symmetric key for the recipient.java.security.NoSuchAlgorithmExceptionjavax.crypto.NoSuchPaddingExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingExceptionjava.security.InvalidKeyExceptionpublic static byte[] decrypt(EncryptedValue encVal, java.security.PrivateKey recipKey) throws java.security.NoSuchAlgorithmException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, java.security.spec.InvalidKeySpecException
EncryptedValue and return the bytes of the value.
For example, to decrypt an EncryptedValue containing a certificate:
// The EncryptedValue.
EncryptedValue encVal = ... ;
// The recipient's private key.
PrivateKey privKey = ... ;
// Decrypt and construct the resulting certificate from
// its DER encoding.
byte[] val = EncryptedValue.decrypt(encVal, privKey);
X509 cert = new X509(val);
Note the changes in the method signature
Previously public static byte[] decrypt (EncryptedValue, oracle.security.crypto.core.PrivateKey )
Now public static byte[] decrypt (EncryptedValue , java.security.PrivateKey )
Note the change in the exceptions declared to be thrown.
Exceptions no longer thrown -- AlgorithmIdentifierException,CipherException
Exceptions introduced -- java.security.InvalidKeyException ,NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException,BadPaddingException,InvalidKeySpecException
encVal - The EncryptedValue to be decrypted.recipKey - The private key of the recipient, corresponding to the public key used by the sender to encrypt.java.security.NoSuchAlgorithmExceptionjavax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.NoSuchPaddingExceptionjava.security.InvalidKeyExceptionjava.security.spec.InvalidKeySpecExceptionpublic byte[] getEncValue()
public void setIntendedAlg(oracle.security.crypto.core.AlgorithmIdentifier intendedAlg)
public oracle.security.crypto.core.AlgorithmIdentifier getIntendedAlg()
public void setSymmAlg(oracle.security.crypto.core.AlgorithmIdentifier symmAlg)
public oracle.security.crypto.core.AlgorithmIdentifier getSymmAlg()
public void setEncSymmKey(byte[] encSymmKey)
public byte[] getEncSymmKey()
public void setKeyAlg(oracle.security.crypto.core.AlgorithmIdentifier keyAlg)
public oracle.security.crypto.core.AlgorithmIdentifier getKeyAlg()
public void setValueHint(byte[] valueHint)
public byte[] getValueHint()
public java.lang.String toString()
toString in class java.lang.Object
public void input(java.io.InputStream is)
throws java.io.IOException
input in interface oracle.security.crypto.util.Streamablejava.io.IOException
public void output(java.io.OutputStream os)
throws java.io.IOException
output in interface oracle.security.crypto.util.Streamablejava.io.IOExceptionpublic int length()
length in interface oracle.security.crypto.util.Streamable