Search in sources :

Example 46 with InvalidCipherTextException

use of org.bouncycastle.crypto.InvalidCipherTextException in project OsmAnd-tools by osmandapp.

the class SigningUtils method encryptPassphrase.

/**
 * Used only for testing: encrypt secret passphrase
 * @param plain plain passphrase
 * @param key secret key
 * @return encrypted passphrase
 * @throws BlockIOException
 */
static byte[] encryptPassphrase(String plain, byte[] key) throws BlockIOException {
    PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new AESEngine());
    CipherParameters aesKey = new KeyParameter(key);
    aes.init(true, aesKey);
    try {
        return cipherData(aes, plain.getBytes("UTF-8"));
    } catch (InvalidCipherTextException e) {
        throw new BlockIOException("Unexpected error while signing transaction. Please file an issue report.");
    } catch (UnsupportedEncodingException e) {
        throw new BlockIOException("Your system does not seem to support UTF-8 encoding! Aborting signing process.");
    }
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) PaddedBufferedBlockCipher(org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher) AESEngine(org.bouncycastle.crypto.engines.AESEngine) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)46 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)13 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)13 AESEngine (org.bouncycastle.crypto.engines.AESEngine)12 CipherParameters (org.bouncycastle.crypto.CipherParameters)11 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)9 IOException (java.io.IOException)7 DataLengthException (org.bouncycastle.crypto.DataLengthException)7 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)7 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)7 GoCipher (com.thoughtworks.go.security.GoCipher)6 Test (org.junit.Test)6 BadPaddingException (javax.crypto.BadPaddingException)5 BlockCipher (org.bouncycastle.crypto.BlockCipher)5 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)5 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ExtendedInvalidCipherTextException (org.openremote.agent.protocol.bluetooth.mesh.utils.ExtendedInvalidCipherTextException)4 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3