Any cocoa source code for AES encryption decryption?

I use a simple category on NSData that uses the built-in CommonCrypto framework to do AES 256-bit encryption. I use this on the Mac but it should work OK on iPhone too: #import <CommonCrypto/CommonCryptor.h> @implementation NSData (AESAdditions) – (NSData*)AES256EncryptWithKey:(NSString*)key { // ‘key’ should be 32 bytes for AES256, will be null-padded otherwise char keyPtr[kCCKeySizeAES256 + … Read more

OpenSSL encryption using .NET classes

Finally figured this one out. In the event someone needs to integrate openssl and .NET without using the openssl wrappers, I’ll share the results here. 1) The main issue with my original code (as in the question) is that you must initialize the BlockSize and KeySize on your RijndaelManaged instance BEFORE setting the key or … Read more

How to decrypt an encrypted AES-256 string from CryptoJS using Java? [closed]

When a message is encrypted in this way: CryptoJS.AES.encrypt(“message”, “passphrase”) a password-based approach is used. For that CryptoJS generates a new salt and uses this salt in conjunction with the passphrase to derive the key and IV (I’ve recreated a derivation function for this question). After the ciphertext is produced a special OpenSSL formatter is … Read more

How to decode a string encoded with openssl aes-128-cbc using java?

Solved it using Bouncy Castle library. Here is the code: package example; import java.util.Arrays; import org.apache.commons.codec.binary.Base64; import org.bouncycastle.crypto.BufferedBlockCipher; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; import org.bouncycastle.crypto.modes.CBCBlockCipher; import org.bouncycastle.crypto.paddings.BlockCipherPadding; import org.bouncycastle.crypto.paddings.PKCS7Padding; import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; public class OpenSSLAesDecrypter { private static final int AES_NIVBITS = 128; // CBC Initialization Vector (same as cipher block size) [16 … Read more

Decrypting AES256 with node.js returns wrong final block length

Ok, so there was a change to Crypto in the switch from 0.8 to 0.10 Crypto methods return Buffer objects by default, rather than binary-encoded strings This means the above code needs to specify encodings. These four lines: decoded = decipher.update(encryptdata); decoded += decipher.final(); encryptdata = encipher.update(cleardata); encryptdata += encipher.final(); Are changed to: decoded = … Read more

AES Encrypt and Decrypt

CryptoSwift Example Updated to Swift 2 import Foundation import CryptoSwift extension String { func aesEncrypt(key: String, iv: String) throws -> String{ let data = self.dataUsingEncoding(NSUTF8StringEncoding) let enc = try AES(key: key, iv: iv, blockMode:.CBC).encrypt(data!.arrayOfBytes(), padding: PKCS7()) let encData = NSData(bytes: enc, length: Int(enc.count)) let base64String: String = encData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)); let result = String(base64String) return result … Read more

AES algo – Decryption Issue

http://android-developers.blogspot.in/2013/02/using-cryptography-to-store-credentials.html http://developer.android.com/reference/javax/crypto/SecretKeyFactory.html Check the above links. Use the below for reference.Modify the below according to your needs. Usage try { DescEncrypter ec = new DescEncrypter(); byte[] cipherText =ec.encrypt(“hi”, “hello”); String enc = new String(cipherText,”UTF-8″); String decryp= ec.decrypt(“hi”, cipherText); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } DescEncrypter.java import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.IvParameterSpec; import … Read more