aes

Why must all inputs to AES be multiples of 16?

六眼飞鱼酱① 提交于 2019-11-30 09:18:56
问题 I'm using the PyCrypto implementation of AES and I'm trying to encrypt some text (24 bytes) using a 24 byte key. aes_ecb = AES.new('\x00'*24, AES.MODE_ECB) aes_ecb.encrypt("123456"*4) I get this surprising error ValueError: Input strings must be a multiple of 16 in length So why is it that my input must be a multiple of 16? It would make more sense to me that the input string length must be a multiple of my key size, because this would allow nice bitwise operations between the key and blocks

AES, Serpent or Twofish in C example?

青春壹個敷衍的年華 提交于 2019-11-30 09:15:27
I found a lot of implementations of AES, Twofish and Serpent in C. But I don't really understand the examples. I only understand that some where provided with examples to invert a matrix. Can someone point me to an example or .c file for to encrypt/decrypt data represented by a char* and a password? The wikipedia article actually links to an excellent tutorial (by X-N20 ) written in C that walks you through the Maths and provides C implementations on the go, which is quite useful for understanding the process. I'd also recommend reading up on finite field arithmetic . Serpent and Twofish ,

Different results in AES256 encryption in Swift (iOS) and PHP

独自空忆成欢 提交于 2019-11-30 09:09:55
I am working in AES256 to be able to encrypt/decrypt between iOS and PHP using insecure channels. I have seen many similar questions that move around the key size, the mode (CBC or ECB), the use of a random iv, etc. But in this case, I found a weird behaviour as follows. Configuration in both environments: - Key: 32 bytes(256 bits) - Block size: 128 bits (standard) - iv: 16 bytes (static for testing purposes) - Mode: CBC If I encrypt a 16 or 32 bytes text (to match the AES block size), the result in Swift, and PHP are similar but not quite the same: key = "12345678901234567890123456789012"

How to handle “last block incomplete in decryption”

泪湿孤枕 提交于 2019-11-30 08:46:49
I have a simple class to try and wrap encryption for use elsewhere in my program. import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.spec.SecretKeySpec; public final class StupidSimpleEncrypter { public static String encrypt(String key, String plaintext) { byte[] keyBytes = key.getBytes(); byte[] plaintextBytes = plaintext.getBytes(); byte[] ciphertextBytes = encrypt(keyBytes, plaintextBytes); return new String(ciphertextBytes); } public static byte[] encrypt(byte[] key, byte[] plaintext) { try { Cipher cipher = Cipher

How can I use ConvertTo-SecureString

那年仲夏 提交于 2019-11-30 08:36:10
问题 Let's say I need to do this in Powershell: $SecurePass = Get-Content $CredPath | ConvertTo-SecureString -Key (1..16) [String]$CleartextPass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($CredPass)); The content of $CredPath is a file that contains the output of ConvertFrom-SecureString -Key (1..16). How do I accomplish the ConvertTo-SecureString -key (1..16) portion in C#/.NET? I know how to create a SecureString , but I'm not sure

Rewrite Rijndael 256 C# Encryption Code in PHP

大兔子大兔子 提交于 2019-11-30 08:20:50
问题 I have an encryption/decryption algorithm written in C# - I need to be able to produce the same encryption in PHP so I can send the encrypted text over HTTP to be decrypted on the C# side. Here is the C# code for the encryption. this.m_plainText = string.Empty; this.m_passPhrase = "passpharse"; this.m_saltValue = "saltvalue"; this.m_hashAlgorithm = "SHA1"; this.m_passwordIterations = 2; this.m_initVector = "1a2b3c4d5e6f7g8h"; this.m_keySize = 256; public string Encrypt() { string plainText =

Android: Encrypt a string with AES 256bit Encryption with iv and secret key

♀尐吖头ヾ 提交于 2019-11-30 08:03:17
SecureRandom random = new SecureRandom(); // quite heavy, look into a lighter method. String stringToEncrypt = "mypassword"; byte[] realiv = new byte[16]; random.nextBytes(realiv); Cipher ecipher = Cipher.getInstance("AES"); SecureRandom random = new SecureRandom(); // quite heavy, look into a lighter method. byte[] realiv = new byte[16]; random.nextBytes(realiv); byte[] secret = "somelongsecretkey".getBytes(); SecretKeySpec secretKey = new SecretKeySpec(secret, "AES"); ecipher.init(Cipher.ENCRYPT_MODE, secretKey, random); byte[] encryptedData = ecipher.doFinal(); but the init() only takes in

Create random 128 bit AES Encryption key in iOS

…衆ロ難τιáo~ 提交于 2019-11-30 07:55:32
I want to create random AES Encryption key (128 bit) in ios. I have searched in SO but I cannot find a good answer. Please give me some advice. thanks in advance. UPDATE: I have used BBAES lib. I used the below code to generate the encryption key but when I convert from NSData to NSString, it shows NULL -(NSData*)randomDataWithLength{ NSData* salt = [BBAES randomDataWithLength:BBAESSaltDefaultLength]; NSData *key = [BBAES keyBySaltingPassword:@"password" salt:salt keySize:BBAESKeySize128 numberOfIterations:BBAESPBKDF2DefaultIterationsCount]; NSLog(@"Data ASE Key %@",key); NSString *aString = [

AES/CBC/PKCS5Padding encrypt in java decrypt in ruby

…衆ロ難τιáo~ 提交于 2019-11-30 07:52:50
I am trying to encrypt data in java and decrypt data in ruby. I found almost same asks, but my case is little bit different. Encrypt in Ruby and Decrypt in Java - Why is it not working? AES/CBC encrypt in Java, decrypt in Ruby My code is ... Encrypt in java import java.util.HashMap; import java.util.Map; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import net.sf.json.JSONObject; import org.apache.commons.codec.binary.Hex; class Crypt { public static void main(String[] args) throws Exception { Map

Why am I getting 'BadPaddingException' when decrypting?

青春壹個敷衍的年華 提交于 2019-11-30 07:45:57
Here are my encryption settings: public static String encryptionAlgorithm = "AES"; public static short encryptionBitCount = 256; public static int encryptionMessageLength = 176; public static String hashingAlgorithm = "PBEWITHSHAAND128BITAES-CBC-BC"; //PBEWithSHA256And256BitAES-CBC-BC"PBEWithMD5AndDES";//"PBKDF2WithHmacSHA1"; public static short hashingCount = 512; public static String cipherTransformation = "AES/CBC/PKCS5Padding"; Here is my code to decrypt: public byte[] readMessage () throws Exception { byte[] iv = new byte[16]; byte[] message = new byte[EncryptionSettings