Methods Summary |
---|
public final java.lang.String | getAlgorithm()Returns the algorithm this object was sealed with.
return sealAlg;
|
public final java.lang.Object | getObject(java.security.Key key)Returns the wrapped object, decrypting it using the specified key.
// BEGIN android-added
if (key == null) {
throw new InvalidKeyException(
Messages.getString("crypto.05"));
}
// END android-added
try {
Cipher cipher = Cipher.getInstance(sealAlg);
if ((paramsAlg != null) && (paramsAlg.length() != 0)) {
AlgorithmParameters params =
AlgorithmParameters.getInstance(paramsAlg);
params.init(encodedParams);
cipher.init(Cipher.DECRYPT_MODE, key, params);
} else {
cipher.init(Cipher.DECRYPT_MODE, key);
}
byte[] serialized = cipher.doFinal(encryptedContent);
ObjectInputStream ois =
new ObjectInputStream(
new ByteArrayInputStream(serialized));
return ois.readObject();
} catch (NoSuchPaddingException e) {
// should not be thrown because cipher text was made
// with existing padding
throw new NoSuchAlgorithmException(e.toString());
} catch (InvalidAlgorithmParameterException e) {
// should not be thrown because cipher text was made
// with correct algorithm parameters
throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalBlockSizeException e) {
// should not be thrown because the cipher text
// was correctly made
throw new NoSuchAlgorithmException(e.toString());
} catch (BadPaddingException e) {
// should not be thrown because the cipher text
// was correctly made
throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalStateException e) {
// should never be thrown because cipher is initialized
throw new NoSuchAlgorithmException(e.toString());
}
|
public final java.lang.Object | getObject(javax.crypto.Cipher c)Returns the wrapped object, decrypting it using the specified
cipher.
if (c == null) {
throw new NullPointerException(Messages.getString("crypto.13")); //$NON-NLS-1$
}
byte[] serialized = c.doFinal(encryptedContent);
ObjectInputStream ois =
new ObjectInputStream(
new ByteArrayInputStream(serialized));
return ois.readObject();
|
public final java.lang.Object | getObject(java.security.Key key, java.lang.String provider)Returns the wrapped object, decrypting it using the specified key. The
specified provider is used to retrieve the cipher algorithm.
if ((provider == null) || (provider.length() == 0)) {
throw new IllegalArgumentException(
Messages.getString("crypto.15")); //$NON-NLS-1$
}
try {
Cipher cipher = Cipher.getInstance(sealAlg, provider);
if ((paramsAlg != null) && (paramsAlg.length() != 0)) {
AlgorithmParameters params =
AlgorithmParameters.getInstance(paramsAlg);
params.init(encodedParams);
cipher.init(Cipher.DECRYPT_MODE, key, params);
} else {
cipher.init(Cipher.DECRYPT_MODE, key);
}
byte[] serialized = cipher.doFinal(encryptedContent);
ObjectInputStream ois =
new ObjectInputStream(
new ByteArrayInputStream(serialized));
return ois.readObject();
} catch (NoSuchPaddingException e) {
// should not be thrown because cipher text was made
// with existing padding
throw new NoSuchAlgorithmException(e.toString());
} catch (InvalidAlgorithmParameterException e) {
// should not be thrown because cipher text was made
// with correct algorithm parameters
throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalBlockSizeException e) {
// should not be thrown because the cipher text
// was correctly made
throw new NoSuchAlgorithmException(e.toString());
} catch (BadPaddingException e) {
// should not be thrown because the cipher text
// was correctly made
throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalStateException e) {
// should never be thrown because cipher is initialized
throw new NoSuchAlgorithmException(e.toString());
}
|
private void | readObject(java.io.ObjectInputStream s)
encodedParams = (byte []) s.readUnshared();
encryptedContent = (byte []) s.readUnshared();
sealAlg = (String) s.readUnshared();
paramsAlg = (String) s.readUnshared();
|