aes

How to decrypt with CryptoJS using AES?

隐身守侯 提交于 2019-12-24 07:05:38
问题 As the question suggests, I can't seem to get a decrypted value correctly using the required options (AES, ECB Mode & PKCS7). I'm encrypting as below: var ENC_KEY = "bXlrZXk="; //"mykey" var encrypted = CryptoJS.AES.encrypt("hello", CryptoJS.enc.Base64.parse(ENC_KEY), { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); console.log('encrypted: ' + encrypted); which works as expected and outputs the encrypted value I expect however when I decrypt this using the below, I end up with an

How to decrypt with CryptoJS using AES?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:05:11
问题 As the question suggests, I can't seem to get a decrypted value correctly using the required options (AES, ECB Mode & PKCS7). I'm encrypting as below: var ENC_KEY = "bXlrZXk="; //"mykey" var encrypted = CryptoJS.AES.encrypt("hello", CryptoJS.enc.Base64.parse(ENC_KEY), { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); console.log('encrypted: ' + encrypted); which works as expected and outputs the encrypted value I expect however when I decrypt this using the below, I end up with an

Securely encrypt integers (up to 2^48) into the shortest possible URL-safe string

纵然是瞬间 提交于 2019-12-24 04:36:07
问题 In my Django application I have hierarchical URL structure: webpage.com/property/PK/sub-property/PK/ etc... I do not want to expose primary keys and create a vulnerability. Therefore I am encrypting all PKs into strings in all templates and URLs. This is done by the wonderful library django-encrypted-id written by this SO user. However, the library supports up to 2^64 long integers and produces 24 characters output (22 + 2 padding). This results in huge URLs in my nested structure. Therefore,

Generate AES key on node

荒凉一梦 提交于 2019-12-24 04:16:08
问题 I'm dealing with a legacy application that uses a custom protocol to cipher communication. Random AES keys are generated in legacy Java app like this: keygen = KeyGenerator.getInstance("AES"); keygen.init(128); keygen.generateKey().getEncoded(); I've been looking for solutions on crypto with no luck. How can I generate this key on nodejs? 回答1: That code probably does not do as much as you think. It simply generates 16 (128 / 8) secure random bytes, then wraps a key object around it. So with

Encrypt binary data with aes-ecb on node.js

别等时光非礼了梦想. 提交于 2019-12-24 03:35:11
问题 I try to do crypto on node.js but badly I fail to have the same result than online sites. I want to encrypt some binary data with a binary key. I use the tutorial on nodejs site but I have a different result from my reference data set. My reference data set is validated with java code, with C code and with two online site : http://aes.online-domain-tools.com/ and https://www.hanewin.net/encrypt/aes/aes-test.htm Have you an idea how to encrypt the same way that those sites? I guess it can be

JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher

二次信任 提交于 2019-12-23 22:03:26
加密代码   + View Code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte [] decrypt( byte [] content, String password) { try { KeyGenerator kgen = KeyGenerator.getInstance( "AES" ); kgen.init( 128 , new SecureRandom(password.getBytes())); SecretKey secretKey = kgen.generateKey(); byte [] enCodeFormat = secretKey.getEncoded(); SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES" ); Cipher cipher = Cipher.getInstance( "AES" ); // 创建密码器 cipher.init(Cipher.DECRYPT_MODE, key); // 初始化

Decrypt MCRYPT_RIJNDAEL_256 with 32-byte initialization vectors with PyCrypto

て烟熏妆下的殇ゞ 提交于 2019-12-23 20:58:46
问题 I have data that was encrypted in PHP as follows: mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SECRET, $data, MCRYPT_MODE_CBC, $iv) I need to decrypt this data in a Python 3 application. I am trying to use PyCrypto but I am open to other libraries. I expect the following to work: decryptor = AES.new(key, mode, IV=IV) plain = decryptor.decrypt(ciphertext) My initialization vector is 32 bytes, and the following exception is thrown: ValueError: IV must be 16 bytes long How can I set PyCrypto to use a 32

Inplace AES CBC/ECB mode encrypting/decrypting using Crypto++

大憨熊 提交于 2019-12-23 19:34:08
问题 Is it explicitly allowed to use the same buffer for plaintext/ciphertext when performing AES encryption/decryption in CBC and ECB modes using Crypto++ (assuming the buffer size is sufficient to accomodate the encrypted data) as in the following code: #include <cstdio> #include <cassert> #include "cryptopp\rsa.h" #include "cryptopp\rijndael.h" #include "cryptopp\modes.h" int main() { using namespace CryptoPP; byte key[32], iv[Rijndael::BLOCKSIZE]; char testdata[] = "Crypto++ Test"; // any data

Symmetric Encryption between .NET and Java

时光毁灭记忆、已成空白 提交于 2019-12-23 17:28:00
问题 I am using a 3rd party platform to create a landing page, it is a business requirement that I use this particular platform. On their page I can encrypt data and send it to my server through a request parameter when calling a resource on my site. This is done through an AES Symmetric Encryption. I need to specify a password, salt (which must be a hex value) and an initialization vector (but be 16 characters). Their backend is a .NET platform. I know this because if I specify an IV longer than

Is Java security module KeyGenerator thread safe? If not then how to fix it?

本小妞迷上赌 提交于 2019-12-23 16:41:38
问题 I have a concurrent encryption/decryption program in which multiple AES128 keys are randomly generated concurrently by invoking the following code (written in scala, the Java version should be fairly similar): private def AESKeyGen: KeyGenerator = { val keyGen = KeyGenerator.getInstance("AES") keyGen.init(128) keyGen } def generateKey: SecretKey = this.synchronized { AESKeyGen.generateKey() } each key is use to encrypt a fixed byte array, then decrypt it by using AESEncrypt and AESDecrypt