cryptojs

AES 256 on the client side (JS) and in the server (PHP)

十年热恋 提交于 2019-12-01 03:27:23
问题 I'm trying to encrypt and decrypt data on the server side and the client using the same type of operation, which is AES-256. On the server I use PHP and client I use CryptoJS so far I could only encrypt and decrypt the client on the server, see the code: JS <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script> <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/pbkdf2.js"></script> <script> var salt = CryptoJS.lib.WordArray.random

Can't verify signature witn Node.js Crypto, using key pairs

柔情痞子 提交于 2019-12-01 02:25:38
I've a very small code in nodejs where I sign a string and then try to verify it, using node crypto and key pairs generated with openssl. No matter what I try, the result is always "false", the signature can't be verified. Generation of public/private key pairs: openssl genrsa -out rsa_1024_priv.pem 1024 openssl rsa -in rsa_1024_priv.pem -out rsa_1024_pub.pem -outform PEM -pubout The resultant keys are (I don't care made them public BTW): -----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQDCtTEic76GBqUetJ1XXrrWZcxd8vJr2raWRqBjbGpSzLqa3YLv VxVeK49iSlI+5uLX/2WFJdhKAWoqO

Decrypting AES with Javascript CryptoJS after encrypting with PHP mcrypt

本小妞迷上赌 提交于 2019-12-01 00:42:18
Encrypting in PHP with mcrypt <?php $string = 'Secret Message'; $key = 'd4b494e4502a62edd695a903a94c2701'; $iv = '02f30dffbb0d084755f438f7d8be4a7d'; $encrypted = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv ) ); //$encrypted results in 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg=' ?> Decrypting in Javascript with CryptoJS <script> var encrypted = 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg='; var key = CryptoJS.enc.Hex.parse('d4b494e4502a62edd695a903a94c2701'); var iv = CryptoJS.enc.Hex.parse('02f30dffbb0d084755f438f7d8be4a7d'); var decrypted =

Can't verify signature witn Node.js Crypto, using key pairs

独自空忆成欢 提交于 2019-11-30 22:45:40
问题 I've a very small code in nodejs where I sign a string and then try to verify it, using node crypto and key pairs generated with openssl. No matter what I try, the result is always "false", the signature can't be verified. Generation of public/private key pairs: openssl genrsa -out rsa_1024_priv.pem 1024 openssl rsa -in rsa_1024_priv.pem -out rsa_1024_pub.pem -outform PEM -pubout The resultant keys are (I don't care made them public BTW): -----BEGIN RSA PRIVATE KEY-----

How does CryptoJS get an IV when none is specified?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 22:25:56
When using CryptoJS.AES.encrypt how does it come up with an Initialization Vector if the third argument is not passed to the function? Is there a way to get it out of the encrypted string? The reason I need this is I need to decrypt something CryptoJS.AES.encrypt returned using Lua, but I only have the key that was provided. CryptoJS' CryptoJS.<BlockCipher>.encrypt has two modes of encryption. If you pass in a key that is not a string , but rather a WordArray (CryptoJS's internal representation format for binary data), the key is taken as-is. This mode expects an IV for all modes of operation

Decrypting AES with Javascript CryptoJS after encrypting with PHP mcrypt

末鹿安然 提交于 2019-11-30 19:59:56
问题 Encrypting in PHP with mcrypt <?php $string = 'Secret Message'; $key = 'd4b494e4502a62edd695a903a94c2701'; $iv = '02f30dffbb0d084755f438f7d8be4a7d'; $encrypted = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv ) ); //$encrypted results in 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg=' ?> Decrypting in Javascript with CryptoJS <script> var encrypted = 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg='; var key = CryptoJS.enc.Hex.parse(

Can't decrypt string with CryptoJS

萝らか妹 提交于 2019-11-30 12:01:43
I'm trying to encode/decode data using CryptoJS, as a preliminar test for the code I want to develop. This is the code I'm using for encrypting: <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script> <script> var message = "Secret Message"; var key = CryptoJS.enc.Hex.parse('36ebe205bcdfc499a25e6923f4450fa8'); var iv = CryptoJS.enc.Hex.parse('be410fea41df7162a679875ec131cf2c'); // Encription. Works ok var encrypted = CryptoJS.AES.encrypt( message,key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } ); console.log('encrypted:'+encrypted

SHA512 hashes differ on android, php and javascript

不问归期 提交于 2019-11-30 10:39:16
I am using the SHA512 hash to transfer some encrypted data between my app and it's backend. However, I'm having a odd situation and have no idea what might be causing it. So, I've got following setups tested: Android 2x SHA512 Android 1x SHA512 -> CryptoJS 1x SHA512 PHP 2x SHA512 So, when I do the first 2x Android hashing, I get the same result as when I do the 1x android -> 1x cryptojs. However, when I do the PHP 2x, I get the same result as I get on the first Android pass, but the second encryption pass of the PHP is different. On PHP, I've tried both the hash() and openssl_digest()

Java to JS and JS to Java encryption using cryptojs

自作多情 提交于 2019-11-30 09:49:49
I got on this post a couple of weeks ago and worked perfectly: Compatible AES algorithm for Java and Javascript Now, I need to do the reverse operation, but once in java, I am getting this exception: javax.crypto.BadPaddingException: Given final block not properly padded at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:966) at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824) at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436) at javax.crypto.Cipher.doFinal(Cipher.java:2165) This is my "reverse" operation I did in JavaScript: var rkEncryptionKey =

AES-256-CBC Mcrypt-PHP decrypt and Crypto-JS Encrypt

假装没事ソ 提交于 2019-11-30 09:36:35
I am trying to encrypt in Javascript with CryptoJS and decrypt in PHP. The JS code is: var salt = CryptoJS.lib.WordArray.random(128/8); var key256Bits500Iterations = CryptoJS.PBKDF2("Secret Passphrase", salt, { keySize: 256/32, iterations: 500 }); var iv = CryptoJS.enc.Hex.parse('101112131415161718191a1b1c1d1e1f'); // just chosen for an example, usually random as well encrypted = CryptoJS.AES.encrypt("Message", key512Bits1000Iterations, { iv: iv }); var data_base64 = crypted.ciphertext.toString(CryptoJS.enc.Base64); var iv_base64 = crypted.iv.toString(CryptoJS.enc.Base64); var key_base64 =