cryptojs

Using the nonce and counter correctly for AES-CTR mode

混江龙づ霸主 提交于 2019-12-05 16:42:17
I understand that in AES Counter mode I need to use a 128 bit nonce. The naïve way to do that would be to use a random 128 bit nonce, but I'm not sure the algorithm will be able to increment the counter correctly if it's passed as all random bits. I thought the correct way to do it is to use a 96 bit nonce and also a 32 bit counter starting at 0, for example: var key = CryptoJS.enc.Hex.parse('01ab23cd45ef67089a1b2c3d4e5f6a7b'); // 128 bits / 16 bytes var nonce = '2301cd4ef785690a1b2c3dab'; // 96 bits / 12 bytes var counter = '00000000'; // 32 bits / 4 bytes var nonceAndCounter = nonce +

Decrypt AES/CBC/PKCS5Padding with CryptoJS

為{幸葍}努か 提交于 2019-12-05 11:04:49
问题 I generate 128bit AES/CBC/PKCS5Padding key using Java javax.crypto API. Here is the algorithm that I use: public static String encryptAES(String data, String secretKey) { try { byte[] secretKeys = Hashing.sha1().hashString(secretKey, Charsets.UTF_8) .toString().substring(0, 16) .getBytes(Charsets.UTF_8); final SecretKey secret = new SecretKeySpec(secretKeys, "AES"); final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secret); final

How to decrypt a file in javascript which is encrypted by JAVA with AES

时光总嘲笑我的痴心妄想 提交于 2019-12-05 10:53:55
问题 I have encrypted JPG file in Java with AES256, but have no idea to decrypt the JPG file in javascript. Anyone has better idea? I'm struggling with it for 4days. byte[] ivBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; String key = "1234567890123456789012345678901d"; AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes); SecretKeySpec newKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance(

How to encrypt a message at client side using crypto-js library and decrypt it at the Java server

大憨熊 提交于 2019-12-05 08:10:08
问题 Background: the application that I am working on is supposed to work offline. I have an HTML5 page and the data keyed in by the user is encrypted using crypto-js library. And I want the encrypted message sent to java webserver and then decrypt it at the server side. What am doing I am able to encrypt the message using Crypto-js <code> var message = "my message text"; var password = "user password"; var encrypted = CryptoJS.AES.encrypt( message ,password ); console.log(encrypted.toString()); /

Aes javascript encrypt - java decrypt

ⅰ亾dé卋堺 提交于 2019-12-05 06:49:29
问题 I'm trying to encrypt a message in javascript (using crypto-js library) and to decrypt it in java. This is the javascript code: var key = CryptoJS.enc.Utf8.parse(aesPassword); var ive = CryptoJS.enc.Utf8.parse(aesIv); var encryptedData = CryptoJS.AES.encrypt(dataToEncrypt, key, {mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, iv: ive}); And this is the java code: final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); final SecretKeySpec key = new SecretKeySpec(aesPassword()

nodejs crypto module vs crypto-js

陌路散爱 提交于 2019-12-05 06:23:04
I'm quite new to NodeJs and trying to figure out how to use the "crypto" module. While playing around with it I notice the difference between the "crypto" module in NodeJs and crypto-js: With crypto-js, I have: function SHA256Hash(password, salt, iteration) { var saltedpassword = salt + password; var sha256 = CryptoJS.algo.SHA256.create(); for(var i = 0; i < iteration; i++) { alert("saltedpassword = " + saltedpassword); sha256.update(saltedpassword); var saltedpassword = sha256.finalize(); sha256.reset(); } return saltedpassword.toString(CryptoJS.enc.Base64); } Then call : var hashedPassword =

Import crypto-js in an angular 2 project (created with angular-cli)

雨燕双飞 提交于 2019-12-05 03:03:56
I'm trying to import crypto-js in my angular2 project. I followed several SO questions and also angular-cli guide , but at the end I still have the error Cannot find module 'crypto-js' What I tried : npm install crypto-js --save and typings install dt~crypto-js --global --save then I modified the file angular-cli-build.js var Angular2App = require('angular-cli/lib/broccoli/angular2-app'); module.exports = function(defaults) { return new Angular2App(defaults, { vendorNpmFiles: [ 'systemjs/dist/system-polyfills.js', 'systemjs/dist/system.src.js', 'zone.js/dist/**/*.+(js|js.map)', 'es6-shim/es6

Encrypting with PHP; decrypting with CryptoJS

百般思念 提交于 2019-12-04 19:35:35
I am having some trouble decrypting data using CryptoJS that was encrypted in PHP. Maybe somebody can advise me on where I am going wrong? I am encrypting as follows: Get hashed password Take substring of (0,16) as the key Encrypt (MCRYPT_RIJNDAEL_128) Encode ciphertext as base64 When decrypting I do the same: Get hashed password Take substring of (0,16) as the key Base64 decode the ciphertext Decrypt PHP: public function encrypt($input, $key) { $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $input = $this->_pkcs5_pad($input, $size); $td = mcrypt_module_open(MCRYPT

Encrypt in javascript and decrypt in C# with AES algorithm

安稳与你 提交于 2019-12-04 17:43:56
I tried to encrypt in angular using AES librery from AES . I encrypt string using the CryptoJS.AES.encrypt() method from AES. here my code: var txtloginKod = 'Some String...'; var key = CryptoJS.enc.Utf8.parse('8080808080808080'); var iv = CryptoJS.enc.Utf8.parse('8080808080808080'); var encryptedlogin = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(txtloginKod), key, { keySize: 128 / 8, iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); The method CryptoJS.AES.encrypt() return a Object to my encryptedlogin variable. I dont know how send this object to my WCF Web server in C# When

CryptoJS AES encryption and JAVA AES decryption value mismatch

浪尽此生 提交于 2019-12-04 14:11:36
问题 I am encrypting a text using CryptoJS AES algorithm on the client side and I am decrypting It on Server side in java, I am getting the exception. JS code : var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase"); console.info("encrypted " + encrypted); var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase"); var plainText = decrypted.toString(CryptoJS.enc.Utf8) console.info("decrypted " + plainText); js output : encrypted U2FsdGVkX1/uYgVsNZmpbgKQJ8KD+8R8yyYn5+irhoI=