aes

How to correctly and consistely get bytes from a string for AES encryption?

百般思念 提交于 2019-12-04 03:22:22
I am currently working on AES implementation in C#. The encryption method has two parameters: a string and a password. I am taking the supplied string and converting it to an array of bytes, so I can use it later for writing data to a stream with BinaryWriter . The problem is that when I use Convert.FromBase64String(string) I get FormatException: Invalid length. and when I use Encoding.UTF8.GetBytes(string) my decryption method throws and invalid PKCS7.Padding exception. I have been trying to solve this problem for the last couple of days. I have read near infinite questions in stackoverflow

Java 7 -> Java 8: AES Causes exception: “BadPaddingException: Given final block not properly padded” in conjunction with BufferedReader & ZipStreams

核能气质少年 提交于 2019-12-04 02:40:17
We instantiate the cipher with the following statement: Cipher cipher = Cipher.getInstance("AES"); SecretKeySpec key = new SecretKeySpec(cipherKey, "AES"); This works in java 7 (1.7_45) but no longer works in Java 8 (1.8_25). We pass the cipher to a CipherInputStream and use the streams to read/write data. The actual exception occurs during close . EDIT: A quick look at the JDK code shows that the BadPaddingException is rethrown and in 7 it was ignored: JDK 7: CipherInputStream.close: try { this.cipher.doFinal(); } catch (BadPaddingException var2) { ; } catch (IllegalBlockSizeException var3) {

Encrypted string From Delphi to C#

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:44:56
问题 i am trying to decrypt one string in c# encrypted in Delphi with Cipher1 3.0, Part I from Delphi Encryption Compendium. I use TCipher_Rijndael. string that i encrypt is : this-is-a-test-example password: pass encrypted values is : iKBC8kX4ZEk4A1pCj6jwEegqjpxhqw== When i try to decrypt this in c# i recive error: Length of the data to decrypt is invalid. Did anyone have the same problem, and what is a solution? Here is a decrypt method in c#: public static byte[] Decrypt(byte[] cipherData, byte

What is the default IV when encrypting with aes_256_cbc cipher?

余生颓废 提交于 2019-12-04 01:37:47
I've generated a random 256 bit symmetric key, in a file, to use for encrypting some data using the OpenSSL command line which I need to decrypt later programmatically using the OpenSSL library. I'm not having success, and I think the problem might be in the initialization vector I'm using (or not using). I encrypt the data using this command: /usr/bin/openssl enc -aes-256-cbc -salt -in input_filename -out output_filename -pass file:keyfile I'm using the following call to initialize the decrypting of the data: EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, keyfile.data(), nullptr))

teamcity aes256-cbc error when retrieving git repository

旧城冷巷雨未停 提交于 2019-12-04 00:39:14
I've just installed Teamcity 8.0.3 on a fresh Windows Server 2012 machine. Installation was successful, and I'm trying to configure an agent in order to fetch a project stored in a git server. This server uses a ssh key. I've added it to my agent, but when it tries to retrieve the project this error appears. Failed for the root 'rtogit' #1: List remote refs failed: com.jcraft.jsch.JSchException: The cipher 'aes256-cbc' is required, but it is not available. I've seen, for example here that I must change my policy, but I'm not a java expert and I don't know what I must do. Can someone help me

Java AES加解密

大憨熊 提交于 2019-12-03 23:59:47
import java.util.Base64; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class CipherEncrptTest { public static void main(String[] args) { //默认加密的salt key String key = "0123abcd0123efmn"; String text = "123456"; try { byte[] raw = key.getBytes("utf-8"); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec iv = new IvParameterSpec(key.getBytes()); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] original = cipher.doFinal(text.getBytes());

Cannot decrypt long AES-256 GCM message with Java

坚强是说给别人听的谎言 提交于 2019-12-03 23:12:37
Related to this question: Cannot decrypt AES-256 GCM with Java The Java decrypt issue seems to only be fixed if the encrypted message is short, i.e. two words or so. I've tried with the words, "hello" and "short string", and both of these words were decrypted fine. When I tried something like, Alphanumeric string test1 with more numbers such as 5, 4, 3, 2, 1 AEADBadTagException came up again. EDIT: This issue is directly related to how long the encrypted message is. Two words is a bit of an exaggeration, but as long as the encrypted message is about as long as this or longer then Java will run

Java (Android) Decrypting msg with IV attached

為{幸葍}努か 提交于 2019-12-03 23:06:20
I generate a random IV, this IV is attached (in plain bytes) to front of the encrypted msg as shown below; public String encrypt(String plainText, byte[] encryptionKey) throws Exception { SecretKeySpec key = new SecretKeySpec(encryptionKey, "AES"); cipher.init(Cipher.ENCRYPT_MODE, key, iV); byte[] data = new byte[iV.getIV().length + plainText.getBytes("UTF-8").length]; // Merge together plain IV and encrypted cipher text System.arraycopy(iV.getIV(), 0, data, 0, iV.getIV().length); System.arraycopy(cipher.doFinal(plainText.getBytes("UTF-8")), 0, data, iV.getIV().length, plainText.getBytes("UTF

Problems encoding/decoding using AES-128-CBC

故事扮演 提交于 2019-12-03 23:06:06
So basically I have these snippets of code and would like them to produce the same output: require 'openssl' aes = OpenSSL::Cipher::Cipher.new("AES-128-CBC") aes.key = "aaaaaaaaaaaaaaaa" aes.iv = "aaaaaaaaaaaaaaaa" aes.encrypt encrypted = aes.update("1234567890123456") << aes.final puts encrypted.unpack('H*').join This prints: 8d3bbffade308f8e4e80cb77ecb8df19ee933f75438cec1315c4a491bd1b83f4 And this Java code: Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); String key = "aaaaaaaaaaaaaaaa"; String textToEncryptpt = "1234567890123456"; SecretKeySpec keyspec = new SecretKeySpec(key

RijndaelManaged supports 128-256 bit key, what key size the default constructor generator?

萝らか妹 提交于 2019-12-03 22:30:56
For new RijndaelManaged(), the documentation says it supports keys of 128 bits and up to 256 bits. When you instantiate new RijndaelManaged(), it creates the Key and IV for you. What size does it default to, 128 bits? The default key size is 256 bits, while the default blocksize is 128 bits. 来源: https://stackoverflow.com/questions/281158/rijndaelmanaged-supports-128-256-bit-key-what-key-size-the-default-constructor