cryptojs

PHP function crypt() in JavaScript

坚强是说给别人听的谎言 提交于 2019-11-28 14:19:06
On the server side I create a password hash: public static function salt() { return '$1$' . StringUtil::random(6, array('encode' => StringUtil::ENCODE_BASE_64)); } public static function hash($password, $salt = null) { return crypt($password, $salt ?: static::salt()); } And on client side I want to do the same using CryptoJS. Is there any analogues in javascript for PHP crypt(), not necessary with CryptoJS? UPD: I want to do this on client side because I don't want to send password to server, but something like clientId crypted with hash, decrypt it on the server and get the hash for the next

How do I make sure the data sent to WebService using jQuery AJAX is through my site and not some attack

自闭症网瘾萝莉.ら 提交于 2019-11-28 14:17:01
My Code: function HandleSignUp() { var CurrentURL = document.URL; var obj, val; //ajax call started $.ajax({ type: "POST", url: "../../webservice/GetAjaxDataWebService.asmx/RegisterNewUser", data: "{'UserFullName': '" + $('#SignUpName').val() + "','Email': '" + $('#SignUpEmail').val() + "','Password': '" + $('#SignUpPassword').val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { //msg.d contains the return value from web service call $.colorbox.close(); val = eval(msg); obj = jQuery.parseJSON(val.d); UpdateLogin(obj.Email, obj.FirstName); }

Different encryption results using C# and CryptoJS

亡梦爱人 提交于 2019-11-28 06:52:38
问题 I encrypt some data using AES in a server application, which is written in C#. I use a predefined key (32 bytes) and IV (16 bytes), for instance... Key: 81fe1681..6a451c1c IV: e83c..ae76 This is my C# code I use to encrypt the data: async Task<byte[]> Encrypt(string privateKey, string pin, byte[] data) { using (var sha = SHA256.Create()) { byte[] keyHash = sha.ComputeHash(Encoding.UTF8.GetBytes($"{privateKey}")); byte[] pinHash = sha.ComputeHash(Encoding.UTF8.GetBytes($"{pin}")); using (Aes

crypto-js aes can't decrypt what it encrypted

眉间皱痕 提交于 2019-11-28 02:10:33
Hello I'm trying to decrypt a encrypted aes string with crypto-js but it seems like it doesn't work right. I'm using: <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script> <script> var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase"); var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase"); </script> But my results are: encrypted: U2FsdGVkX19whKq54yOQt3l1erbtEtn/M0qJjAH+E/E= decrypted: 4d657373616765 My expectation was the it returns back "Message". What am I missing? The return type of all CryptoJS.<blockcipher>.decrypt()

JavaScript File Hash Value Generate with Part of the file

不羁岁月 提交于 2019-11-28 01:50:37
问题 I am working with JavaScript to generate File HASH VALUE for unique file values. Kindly check the below code for the Hash Generation Mechanism Which works good. <script type="text/javascript"> // Reference: https://code.google.com/p/crypto-js/#MD5 function handleFileSelect(evt) { var files = evt.target.files; // FileList object // Loop through the FileList and render image files as thumbnails. for (var i = 0, f; f = files[i]; i++) { var reader = new FileReader(); // Closure to capture the

How to properly sign a GET request to Amazon's ItemLookup using client-side JavaScript only?

江枫思渺然 提交于 2019-11-28 01:13:56
问题 Here's what I have so far: function sha256(stringToSign, secretKey) { return CryptoJS.HmacSHA256(stringToSign, secretKey); } function getAmazonItemInfo(barcode) { var parameters = "Service=AWSECommerceService&" + "AWSAccessKeyId=" + appSettings.amazon.accessKey + "&" + "Operation=ItemLookup&" + "ItemId=" + barcode + "&Timestamp=" + Date.now().toString(); var stringToSign = "GET\n" + "webservices.amazon.com\n" + "/onca/xml\n" + parameters; var signature = "&Signature=" + encodeURIComponent

AES Encrypt in CryptoJS and decrypt in Coldfusion

时光怂恿深爱的人放手 提交于 2019-11-27 23:13:58
We've got a Silent Login service written in Coldfusion9 that accepts encrypted strings from external systems and then decrypts based on an agreed Algorithm/Encoding setup. This has worked without issue for years now from systems running ASP/JAVA/PHP, but we now have a client who has no choice but to use CryptoJS to perform the encryption and for the life of me I cannot work out why this won't decrypt in Coldfusion. My knowledge of encryption isn't brilliant but the thing I am noticing is the CryptoJS encrypted ciphertext for the exact same string/key differs every time i perform the encryption

How to get digest representation of CryptoJS.HmacSHA256 in JS

无人久伴 提交于 2019-11-27 23:08:23
I have to generate string representation of CryptoJS.HmacSHA256 in digest (bytes representation). I need it because i have to duplicate python code which generate such digest in javascript: print hmac.new("secret", "test", hashlib.sha256).digest() ')�kb��>�y+������:�o��H� ' The goal is to duplicate behaviour of code above in javascript. Could you please suggest me how to do this? If you need raw bytes then CryptoJS does not seem to supply code for it. It is mentioned that this is because of lack of cross browser compatibility for Uint8Array and friends. However, after searching, I did find

CryptoJS AES encryption and Java AES decryption

这一生的挚爱 提交于 2019-11-27 14:07:44
I'm only asking this because I have read many posts for 2 days now about crypto AES encryption, and just when I thought I was getting it, I realized I wasn't getting it at all. This post is the closest one to my issue, I have exactly the same problem but it is unanswered: CryptoJS AES encryption and JAVA AES decryption value mismatch I have tried doing it in many ways but I haven't gotten it right. First Off I'm getting the already encrypted string (I only got the code to see how they were doing it), so modifying the encryption way is not an option. That's why all the similar questions aren't

Encrypt in PHP openssl and decrypt in javascript CryptoJS

浪子不回头ぞ 提交于 2019-11-27 12:13:51
I'm encrypting some parameters in PHP using openssl("parameter", "AES-256-ECB", "client") and I wish to decrypt in CryptoJS : CryptoJS.AES.decrypt(parameter, "client", {mode: CryptoJS.mode.ECB}).toString(CryptoJS.enc.Utf8); but it's throwing an empty string. Any suggestions? CryptoJS: PHP openssl encrypt -> javascript decrypt PHP: function CryptoJSAesEncrypt($passphrase, $plain_text){ $salt = openssl_random_pseudo_bytes(256); $iv = openssl_random_pseudo_bytes(16); //on PHP7 can use random_bytes() istead openssl_random_pseudo_bytes() //or PHP5x see : https://github.com/paragonie/random_compat