cryptography

Recreating a CryptoJS Hmac using python

跟風遠走 提交于 2021-02-11 13:55:55
问题 The scenario is that I have a JS script that creates a HMAC for a user provided input and I want to compute the same HMAC for the same input using python. To make things clearer, consider the following JS and Python code snippets. Javascript <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs

Using node.js to decrypt data encrypted using c#

孤者浪人 提交于 2021-02-11 08:56:10
问题 I'm facing a issue now which need you guys help. I use c# to do some encryption. Then need to use node.js to decry-pt it. But I just found that I can't do it correctly base on my c# encryption algorithm. If you guys have any solution, please help me. Here is my c# encryption code: public static string Encrypt(string text, String password, string salt, string hashAlgorithm, int passwordIterations, string initialVector, int keySize) { if (string.IsNullOrEmpty(text)) return ""; var

Using node.js to decrypt data encrypted using c#

眉间皱痕 提交于 2021-02-11 08:55:10
问题 I'm facing a issue now which need you guys help. I use c# to do some encryption. Then need to use node.js to decry-pt it. But I just found that I can't do it correctly base on my c# encryption algorithm. If you guys have any solution, please help me. Here is my c# encryption code: public static string Encrypt(string text, String password, string salt, string hashAlgorithm, int passwordIterations, string initialVector, int keySize) { if (string.IsNullOrEmpty(text)) return ""; var

Encrypt AES/CBC/PKCS7Padding

坚强是说给别人听的谎言 提交于 2021-02-11 07:44:58
问题 Help me to make encryption AES/CBC/PKCS7Padding ? Below is my code to decrypt AES/CBC/PKCS7 . It's working but when I encrypt some string and decrypt from my self it's error. Below i adding code to encrypt and decrypt AES/CBC/PKCS7Padding. - (NSData *)AES256Encrypt:(id)key { NSString *iv = @"FEDCBA9876543210"; NSData *keyPtr = [key copy]; size_t dataLength = [self length]; NSData *ivPtr = [iv dataUsingEncoding:NSUTF8StringEncoding]; //NSData *encrypted = [self subdataWithRange:NSMakeRange(0,

Encrypt AES/CBC/PKCS7Padding

痴心易碎 提交于 2021-02-11 07:44:11
问题 Help me to make encryption AES/CBC/PKCS7Padding ? Below is my code to decrypt AES/CBC/PKCS7 . It's working but when I encrypt some string and decrypt from my self it's error. Below i adding code to encrypt and decrypt AES/CBC/PKCS7Padding. - (NSData *)AES256Encrypt:(id)key { NSString *iv = @"FEDCBA9876543210"; NSData *keyPtr = [key copy]; size_t dataLength = [self length]; NSData *ivPtr = [iv dataUsingEncoding:NSUTF8StringEncoding]; //NSData *encrypted = [self subdataWithRange:NSMakeRange(0,

Hash large files with crypto.subtle.digest(“SHA-256”, buffer)

青春壹個敷衍的年華 提交于 2021-02-11 07:18:25
问题 i have developed a web application where a user can select multiple files via a input field. Then the sha-256 checksums are calculated by the following code. The code (taken from developer.mozilla.org) only works for small files. What do I have to change to handle large files (e.g. 1GB+) too? function sha256(buffer){ return crypto.subtle.digest("SHA-256", buffer).then(function (hash) { return hex(hash); }); } function hex(buffer) { var hexCodes = []; var view = new DataView(buffer); for (var

How to validate ES384 JWT signature with x and y coordinate in python

坚强是说给别人听的谎言 提交于 2021-02-10 15:13:41
问题 I have a JWT that is as follows: Authorization: Bearer eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCIsImtpZCI6IjQ0ODIzZjNkLTBiMDEtNGE2Yy1hODBlLWI5ZDNlOGE3MjI2ZiIsImprdSI6Imh0dHBzOi8vc2FuZGJveC5jZHMtaG9va3Mub3JnLy53ZWxsLWtub3duL2p3a3MuanNvbiJ9.eyJpc3MiOiJodHRwczovL3NhbmRib3guY2RzLWhvb2tzLm9yZyIsImF1ZCI6Imh0dHA6Ly8xMjcuMC4wLjE6ODAwMC9jZHMtc2VydmljZXMiLCJleHAiOjE1OTQyMzA5MDAsImlhdCI6MTU5NDIzMDYwMCwianRpIjoiZWZiMzc3M2QtM2EyOC00M2UyLTlmYmMtYjkzNmE5YWUzODhiIn0.Cbey3n5NkDRoCLHZ2WMFc1z

How to validate ES384 JWT signature with x and y coordinate in python

我的未来我决定 提交于 2021-02-10 15:12:06
问题 I have a JWT that is as follows: Authorization: Bearer eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCIsImtpZCI6IjQ0ODIzZjNkLTBiMDEtNGE2Yy1hODBlLWI5ZDNlOGE3MjI2ZiIsImprdSI6Imh0dHBzOi8vc2FuZGJveC5jZHMtaG9va3Mub3JnLy53ZWxsLWtub3duL2p3a3MuanNvbiJ9.eyJpc3MiOiJodHRwczovL3NhbmRib3guY2RzLWhvb2tzLm9yZyIsImF1ZCI6Imh0dHA6Ly8xMjcuMC4wLjE6ODAwMC9jZHMtc2VydmljZXMiLCJleHAiOjE1OTQyMzA5MDAsImlhdCI6MTU5NDIzMDYwMCwianRpIjoiZWZiMzc3M2QtM2EyOC00M2UyLTlmYmMtYjkzNmE5YWUzODhiIn0.Cbey3n5NkDRoCLHZ2WMFc1z

Convert number to ArrayBuffer

别等时光非礼了梦想. 提交于 2021-02-10 12:21:19
问题 I'm trying to decrypt data on the browser using the AES-CTR algo. The WebCrypto API requires the counter to be passed as a BufferSource. How do I convert the counter (a number) to the expected input (a byte array)? I'm using an all zero IV, so the counter starts at 0. Let's say I'm trying to decrypt data where counter = 445566. How do I convert 445566 into an ArrayBuffer? const key = // retrieve decryption key const encrypted = // retrieve encrypted data const iv = new ArrayBuffer(16) // iv

Convert openssl AES in Php to Python AES

大兔子大兔子 提交于 2021-02-10 06:14:45
问题 I have a php file which is as follow: $encryption_encoded_key = 'c7e1wJFz+PBwQix80D1MbIwwOmOceZOzFGoidzDkF5g='; function my_encrypt($data, $key) { $encryption_key = base64_decode($key); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cfb')); $encrypted = openssl_encrypt($data, 'aes-256-cfb', $encryption_key, 1, $iv); // The $iv is just as important as the key for decrypting, so save it with encrypted data using a unique separator (::) return base64_encode($encrypted . '::'