aes

AES-256 CBC encrypt in php and decrypt in Java or vice-versa

故事扮演 提交于 2019-12-18 13:52:08
问题 JAVA import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; class AES256JavaPhp{ public static void main(String[] args) throws Exception { Base64 base64 = new Base64(); Cipher ciper = Cipher.getInstance("AES/CBC/PKCS5Padding"); SecretKeySpec key = new SecretKeySpec("PasswordPassword".getBytes("UTF-8"),"AES"); IvParameterSpec iv = new IvParameterSpec ("dynamic@dynamic@".getBytes("UTF-8"),0

Encrypt in Objective-C / Decrypt in Ruby using anything

情到浓时终转凉″ 提交于 2019-12-18 13:48:12
问题 We are using this code to encrypt in Objective-C on the iPhone: - (NSMutableData*) EncryptAES: (NSString *) key { char keyPtr[kCCKeySizeAES128+1]; bzero( keyPtr, sizeof(keyPtr) ); [key getCString: keyPtr maxLength: sizeof(keyPtr) encoding: NSUTF8StringEncoding]; size_t numBytesEncrypted = 0; NSUInteger dataLength = [self length]; size_t bufferSize = dataLength + kCCBlockSizeAES128; void *buffer = malloc(bufferSize); NSMutableData *output = [[NSData alloc] init]; CCCryptorStatus result =

AES Error: Given final block not properly padded

痴心易碎 提交于 2019-12-18 13:48:10
问题 I need help with this error: Given final block not properly padded. As you can see from the title, I am working with AES. Here is the code of line where is error: byte[] decrypted = cipher.doFinal(bytes); Here is the full code: public class AESCrypt { private final Cipher cipher; private final SecretKeySpec key; private String encryptedText, decryptedText; public AESCrypt(String password) throws Exception { // hash password with SHA-256 and crop the output to 128-bit for key MessageDigest

How AES in CTR works for Python with PyCrypto?

橙三吉。 提交于 2019-12-18 13:41:21
问题 I am using python 2.7.1 I want to encrypt sth using AES in CTR mode. I installed PyCrypto library for python. I wrote the following code: secret = os.urandom(16) crypto = AES.new(os.urandom(32), AES.MODE_CTR, counter=lambda: secret) encrypted = crypto.encrypt("asdk") print crypto.decrypt(encrypted) i have to run crypto.decrypt as many times as the byte size of my plaintext in order to get correctly the decrypted data. I.e: encrypted = crypto.encrypt("test") print crypto.decrypt(encrypted)

SQL Encrypted Columns in WHERE Clause

空扰寡人 提交于 2019-12-18 13:04:15
问题 I am looking to apply SQL column level encryption using symmetric keys. The initial steps needed to create the Database Master Key, Certificates and Symmetric Keys seems straight forward and I have tested encrypting/decrypting data using Symmetric Keys successfully. However, once the data is encrypted I don't know how best to query it. E.g. SELECT PlainTextA, PlainTextB, PlainTextC WHERE CONVERT(varchar, DECRYPTBYKEY(EncyptedColumn)) = @SearchTerm would surely result in a full table scan?

AES Encryption in Golang and Decryption in Java

為{幸葍}努か 提交于 2019-12-18 12:45:32
问题 I have the following AES Encryption function written in Golang. func encrypt(key []byte, text string) string { plaintext := []byte(text) block, err := aes.NewCipher(key) if err != nil { panic(err) } ciphertext := make([]byte, aes.BlockSize+len(plaintext)) iv := ciphertext[:aes.BlockSize] if _, err := io.ReadFull(rand.Reader, iv); err != nil { panic(err) } stream := cipher.NewCFBEncrypter(block, iv) stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext) return base64.URLEncoding

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

落爺英雄遲暮 提交于 2019-12-18 12:42:59
问题 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

Why am I getting 'BadPaddingException' when decrypting?

情到浓时终转凉″ 提交于 2019-12-18 12:42:41
问题 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 ()

c# AES Decryption

陌路散爱 提交于 2019-12-18 12:38:38
问题 I am working with SagePay Forms and currently converting the VB examples they have to c#. I have made good progress so the encryption part of my project works fine (SagePay can decrypt it). The issue I am having is that when I attempt to decrypt the string, it turns to garbage. If anyone has done this before I would really appreciate some help with my decryption code. I have included the encryption code which works and the first two lines are the setup and call from another method. I haven't

javax.crypto.IllegalBlockSizeException: last block incomplete in decryption - Decrypting an encrypted AES String

别说谁变了你拦得住时间么 提交于 2019-12-18 11:53:37
问题 I am trying to decrypt the string "~9?8?m???=?T?G" that I receive from a back-end server which uses OpenSSL to encrypt the String using AES-256-CBC. There is the code block: public static String decryptText(String textToDecrypt) { try { byte[] base64TextToDecrypt = Base64.encodeBase64(textToDecrypt.getBytes("UTF-8")); byte[] guid = "fjakdsjkld;asfj".getBytes("UTF-8"); byte[] iv = new byte[16]; System.arraycopy(guid, 0, iv, 0, guid.length); IvParameterSpec ips = new IvParameterSpec(iv); byte[]