aes

Porting Node 'crypto' code to Java

微笑、不失礼 提交于 2019-12-11 13:32:59
问题 I'm trying to port this JS code to Java. I have tried using BoucyCastle without success. The output was not consistent. var crypto = require('crypto'), algorithm = 'aes-256-ctr', password = '000000000000000000000000'; function encrypt(text) { var cipher = crypto.createCipher(algorithm, password) var crypted = cipher.update(text, 'utf8', 'hex') crypted += cipher.final('hex'); return crypted; } var encrypted = encrypt("0") console.log(encrypted); Any ideas ? EDIT: This is not a duplicate as the

Where to put information about padding length?

自作多情 提交于 2019-12-11 13:17:28
问题 I'm working on AES encryptor and decryptor. I've decided to use PKCS#7. And now, I've no idea where to put information about padding length. I've read that I can read last byte (==n) and check if it's lower than 16. If it's true i can check n bytes if they are equal n. But here is a thing. What if the last block to encrypt has 16 bytes and looks like this for exmaple: {0x01, 0xfa,..., 0xf1, 0x02, 0x02} After decryption, decryptor will read it and decide that two last bytes are padded (in fact

C# - AESCng Why Encrypt/Decrypt byte array greater than 127 incorrectly?

孤者浪人 提交于 2019-12-11 12:57:14
问题 when I encrypt and decrypt byte[128] { 1, 2, ..., 126, 127 } by AES, everything is fine: // Create Key & iv byte[] key = GenerateKey(); byte[] iv = GenerateIV(); // Create raw byte array 0-127 byte[] raw = new byte[128]; for (byte i = 0; i < 128; i++) { raw[i] = i; } // Encrypt var encrypted = Encrypt(raw, key, iv); // Decrypt var decrypted = Decrypt(encrypted, key, iv); decrypted will output byte[128] { 1, 2, ..., 126, 127 }. but when I change raw to byte[127] { 128, 129, ..., 253, 254 } to

HTTP Request encrypt & decrypt failure with PHP & Objective-C

半城伤御伤魂 提交于 2019-12-11 12:21:43
问题 I have an issue with HTTP POST requests encrypting & decrypting. I have an OS X Application written in Objective-C which sends encrypted (CocoaSecurity) HTTP POST request to server: - (NSString *)secure { NSData* key = [@"9eab87dc72b927c9" dataUsingEncoding:NSASCIIStringEncoding]; NSData* iv = [@"d6f8f85911c4d8d1" dataUsingEncoding:NSASCIIStringEncoding]; CocoaSecurityResult *result = [CocoaSecurity aesEncrypt:@"a" key:key iv:iv]; return result.hexLower; } and I am getting encryption

Encrypt String AES Windows Phone 8.1

元气小坏坏 提交于 2019-12-11 12:08:23
问题 I'm making an app which will need to encrypt a string. I'm completely new to AES encryption. I have to code that runs on the server to encrypt. public static string Encrypt(string text, byte[] key, byte[] iv, int keysize = 128, int blocksize = 128, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7) { AesCryptoServiceProvider aes = new AesCryptoServiceProvider(); aes.BlockSize = blocksize; aes.KeySize = keysize; aes.Mode = cipher; aes.Padding = padding; byte[] src =

Can I use PKCS5Padding padding algorithm while decryption for already encrypted data using PKCS7Padding?

久未见 提交于 2019-12-11 11:56:53
问题 I'm replacing PKCS7Padding padding with PKCS5Padding for my AES encryptions. Can I use PKCS5Padding padding algorithm while decryption for already encrypted data using PKCS7Padding? I tried using a sample program on local and somehow it works and didn't give any error. Just want to ensure if we need any sort of Migration for all the existing records. For all the existing records, Do I need to decrypt first using PKCS7Padding and then again encrypt using PKCS5Padding and store it back in the

Translating AesManaged to new universal app CryptographicEngine

好久不见. 提交于 2019-12-11 10:31:19
问题 I've this old code snipped that should be translated to use the new CryptographicEngine. But I'm overwhelmed by the possibilities of the new API. Can someone plz help me? private AesManaged GetAes(string textkey) { var aes = new AesManaged(); aes.IV = new byte[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var key = System.Text.Encoding.UTF8.GetBytes(textkey); aes.Key = key; return aes; } private string DecryptValue(string input, string textkey) { var bytes = Convert.FromBase64String

objective c aes 128 encryption for a c# web service

情到浓时终转凉″ 提交于 2019-12-11 10:15:37
问题 So I'm trying to figure out how to make an objective c version of this as it's part of a wcf service security that was implemented. My main issue here is Idk where to begin as some articles/tutorials would automatically pad 0 in the beginning (not sure if that's their IV) like so: (a couple of replies down) http://iphonedevsdk.com/forum/iphone-sdk-development/60926-aesencryption-in-objective-c-and-php.html compared to this which doesn't use any padding: Objective-C decrypt AES 128 cbc hex

Why can't C# decrypt the output from Perl's Crypt::Rijndael?

▼魔方 西西 提交于 2019-12-11 10:15:14
问题 A file has been encrypted by Perl. Initial decrypt attempts failed and I am now trying to ascertain whether there is any hoojoo going on (some other settings required) Duff Perl Code: use strict; use Crypt::Rijndael; my $key ='...'; my $rcipher = Crypt::Rijndael->new ($key, Crypt::Rijndael::MODE_CBC()); undef $/; my $encrypted = <>; print $rcipher->decrypt($encrypted); C# Decryption Implementation CryptoStream decryptor = null; StreamReader srDecrypt = null; FileStream fsIn = null;

C# Decrypting mp3 file using RijndaelManaged and CryptoStream

℡╲_俬逩灬. 提交于 2019-12-11 09:18:41
问题 I have decrypted and saved an mp3 file into a blob storage. However, when I decrypt and download the file I cant play it. I used an Mp3 validation tool which says "unknown file format". I believe it is the decryption that does not work since it works to download an unencrypted Mp3 file. Below I first show the encryption code within its Azure webjob function. The I show the decryption method and the method using it. I have removed handling of keys and such or clarity. Encrypt public static