本文整理匯總了Java中org.bouncycastle.crypto.InvalidCipherTextException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java InvalidCipherTextException.getMessage方法的具體用法?Java InvalidCipherTextException.getMessage怎麽用?Java InvalidCipherTextException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.crypto.InvalidCipherTextException
的用法示例。
在下文中一共展示了InvalidCipherTextException.getMessage方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateUnwrappedKey
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
throws OperatorException
{
AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());
keyCipher.init(false, privateKey);
try
{
byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);
if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
{
return new GenericKey(encryptedKeyAlgorithm, key);
}
else
{
return new GenericKey(encryptedKeyAlgorithm, key);
}
}
catch (InvalidCipherTextException e)
{
throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
}
}
示例2: engineDoFinal
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
protected byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException, BadPaddingException
{
if (inputLen != 0)
{
buffer.write(input, inputOffset, inputLen);
}
try
{
byte[] buf = buffer.toByteArray();
buffer.reset();
return cipher.processBlock(buf, 0, buf.length);
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
示例3: engineDoFinal
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
protected byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException, BadPaddingException
{
cipher.processBytes(input, inputOffset, inputLen);
try
{
return cipher.doFinal();
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
示例4: extractSecretKey
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
protected KeyParameter extractSecretKey(AlgorithmIdentifier keyEncryptionAlgorithm, AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
throws CMSException
{
Wrapper keyEncryptionCipher = EnvelopedDataHelper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());
keyEncryptionCipher.init(false, new ParametersWithIV(new KeyParameter(derivedKey), ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets()));
try
{
return new KeyParameter(keyEncryptionCipher.unwrap(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length));
}
catch (InvalidCipherTextException e)
{
throw new CMSException("unable to unwrap key: " + e.getMessage(), e);
}
}
示例5: aesEncrypt
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public static byte[] aesEncrypt(byte[] plaintext, byte[] myPrivateKey, byte[] theirPublicKey, byte[] nonce) {
try {
byte[] dhSharedSecret = new byte[32];
Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
for (int i = 0; i < 32; i++) {
dhSharedSecret[i] ^= nonce[i];
}
byte[] key = sha256().digest(dhSharedSecret);
byte[] iv = new byte[16];
secureRandom.get().nextBytes(iv);
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(true, ivAndKey);
byte[] output = new byte[aes.getOutputSize(plaintext.length)];
int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
ciphertextLength += aes.doFinal(output, ciphertextLength);
byte[] result = new byte[iv.length + ciphertextLength];
System.arraycopy(iv, 0, result, 0, iv.length);
System.arraycopy(output, 0, result, iv.length, ciphertextLength);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例6: engineDoFinal
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException, BadPaddingException
{
if (inputLen != 0)
{
buffer.write(input, inputOffset, inputLen);
}
try
{
byte[] buf = buffer.toByteArray();
buffer.reset();
return cipher.processBlock(buf, 0, buf.length);
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
示例7: aesEncrypt
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public static byte[] aesEncrypt(byte[] plaintext, byte[] myPrivateKey, byte[] theirPublicKey) {
try {
byte[] dhSharedSecret = new byte[32];
Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
byte[] key = sha256().digest(dhSharedSecret);
byte[] iv = new byte[16];
secureRandom.get().nextBytes(iv);
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(true, ivAndKey);
byte[] output = new byte[aes.getOutputSize(plaintext.length)];
int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
ciphertextLength += aes.doFinal(output, ciphertextLength);
byte[] result = new byte[iv.length + ciphertextLength];
System.arraycopy(iv, 0, result, 0, iv.length);
System.arraycopy(output, 0, result, iv.length, ciphertextLength);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例8: aesDecrypt
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public static byte[] aesDecrypt(byte[] ivCiphertext, byte[] myPrivateKey, byte theirPublicKey[]) {
try {
if (ivCiphertext.length < 16 || ivCiphertext.length % 16 != 0) {
throw new InvalidCipherTextException("invalid ciphertext");
}
byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
byte[] dhSharedSecret = new byte[32];
Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
byte[] key = sha256().digest(dhSharedSecret);
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(false, ivAndKey);
byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
plaintextLength += aes.doFinal(output, plaintextLength);
byte[] result = new byte[plaintextLength];
System.arraycopy(output, 0, result, 0, result.length);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例9: build
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public PBESecretKeyDecryptor build(char[] passPhrase)
{
return new PBESecretKeyDecryptor(passPhrase, calculatorProvider)
{
public byte[] recoverKeyData(int encAlgorithm, byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen)
throws PGPException
{
try
{
BufferedBlockCipher c = BcUtil.createSymmetricKeyWrapper(false, BcImplProvider.createBlockCipher(encAlgorithm), key, iv);
byte[] out = new byte[keyLen];
int outLen = c.processBytes(keyData, keyOff, keyLen, out, 0);
outLen += c.doFinal(out, outLen);
return out;
}
catch (InvalidCipherTextException e)
{
throw new PGPException("decryption failed: " + e.getMessage(), e);
}
}
};
}
示例10: encryptSessionInfo
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
protected byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] sessionInfo)
throws PGPException
{
try
{
BlockCipher engine = BcImplProvider.createBlockCipher(encAlgorithm);
BufferedBlockCipher cipher = BcUtil.createSymmetricKeyWrapper(true, engine, key, new byte[engine.getBlockSize()]);
byte[] out = new byte[sessionInfo.length];
int len = cipher.processBytes(sessionInfo, 0, sessionInfo.length, out, 0);
len += cipher.doFinal(out, len);
return out;
}
catch (InvalidCipherTextException e)
{
throw new PGPException("encryption failed: " + e.getMessage(), e);
}
}
示例11: generateUnwrappedKey
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
throws OperatorException
{
wrapper.init(false, wrappingKey);
try
{
return new GenericKey(encryptedKeyAlgorithm, wrapper.unwrap(encryptedKey, 0, encryptedKey.length));
}
catch (InvalidCipherTextException e)
{
throw new OperatorException("unable to unwrap key: " + e.getMessage(), e);
}
}
示例12: engineDoFinal
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
protected byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException, BadPaddingException
{
if (input != null)
{
bOut.write(input, inputOffset, inputLen);
}
if (cipher instanceof RSABlindedEngine)
{
if (bOut.size() > cipher.getInputBlockSize() + 1)
{
throw new ArrayIndexOutOfBoundsException("too much data for RSA block");
}
}
else
{
if (bOut.size() > cipher.getInputBlockSize())
{
throw new ArrayIndexOutOfBoundsException("too much data for RSA block");
}
}
try
{
byte[] bytes = bOut.toByteArray();
bOut.reset();
return cipher.processBlock(bytes, 0, bytes.length);
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
示例13: aesDecrypt
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public static byte[] aesDecrypt(byte[] ivCiphertext, byte[] myPrivateKey, byte[] theirPublicKey, byte[] nonce) {
try {
if (ivCiphertext.length < 16 || ivCiphertext.length % 16 != 0) {
throw new InvalidCipherTextException("invalid ciphertext");
}
byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
byte[] dhSharedSecret = new byte[32];
Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
for (int i = 0; i < 32; i++) {
dhSharedSecret[i] ^= nonce[i];
}
byte[] key = sha256().digest(dhSharedSecret);
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(false, ivAndKey);
byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
plaintextLength += aes.doFinal(output, plaintextLength);
byte[] result = new byte[plaintextLength];
System.arraycopy(output, 0, result, 0, result.length);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例14: doFinal
import org.bouncycastle.crypto.InvalidCipherTextException; //導入方法依賴的package包/類
public int doFinal(byte[] out, int outOff) throws IllegalStateException, BadPaddingException
{
try
{
return cipher.doFinal(out, outOff);
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}