Tag: aes

在iOS 7中,AES解密在iOS 8/9中具有不同的行为

以下方法在iOS 7上运行时会返回不同的结果,而不是在iOS 8/9上运行。 + (NSData *)decryptData:(NSData *)data key:(NSData *)key iv:(NSData *)iv; { NSData *result = nil; // setup key unsigned char cKey[FBENCRYPT_KEY_SIZE]; bzero(cKey, sizeof(cKey)); [key getBytes:cKey length:FBENCRYPT_KEY_SIZE]; // setup iv char cIv[FBENCRYPT_BLOCK_SIZE]; bzero(cIv, FBENCRYPT_BLOCK_SIZE); if (iv) { [iv getBytes:cIv length:FBENCRYPT_BLOCK_SIZE]; } // setup output buffer size_t bufferSize = [data length] + FBENCRYPT_BLOCK_SIZE; void *buffer = […]

AESencryption在iOS和Android中造成不同的结果

尝试使用Android和iOS中的CBC和PKCS7填充使用AES128algorithm对样本数据进行encryption,但结果不同:( Android代码: private static final byte[] KEY = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}; int srcBuffSiz = 1024; byte[] srcBuff = new byte[srcBuffSiz]; Arrays.fill(srcBuff, (byte)0x01); SecretKeySpec skeySpec = new SecretKeySpec(KEY, "AES"); Cipher ecipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); ecipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] dstBuff = ecipher.doFinal(srcBuff); int bytesEncrypted = […]

aes 128消息解密 – Swift,iOS

我试图用下面的代码128密钥解密消息。 这是string的扩展: func aesDecrypt(key:String, iv:String, options:Int = kCCOptionPKCS7Padding) -> String? { if let keyData = key.dataUsingEncoding(NSUTF8StringEncoding), data = NSData(base64EncodedString: self, options: .IgnoreUnknownCharacters), cryptData = NSMutableData(length: Int((data.length)) + kCCBlockSizeAES128) { let keyLength = size_t(kCCKeySizeAES128) let operation: CCOperation = UInt32(kCCDecrypt) let algoritm: CCAlgorithm = UInt32(kCCAlgorithmAES128) let options: CCOptions = UInt32(options) var numBytesEncrypted :size_t = 0 let cryptStatus […]

在iOS中解码OpenSSL AES256string

CLI $ echo -n "TEST1" | openssl enc -aes256 -k FUUU -nosalt -a bYbkQJcDFZt3y3UQEMbEeg== iOS版 NSString *leSYT = @"bYbkQJcDFZt3y3UQEMbEeg=="; NSData *data = [NSData dataFromBase64String:leSYT]; NSLog(@"%@",[data AES256DecryptWithKey:@"FUUU"]); iOS失败后不输出任何内容。 我错过了什么? NSData增加: http : //pastie.org/426530 // Matt Gallagher的NSData + Base64

Objective-C解密AES 128 cbchexstring

我正在开发Snow Leopard上的iPhone应用程序,使用Xcode 3.1从一个宁静的Web服务接收一个带有algorithmAES 128位(CBC)的hex格式的encryption文本。 该algorithm使用初始化向量+秘密密钥。 我如何解密这个文本? 感谢大家的提示,我会成功给予。 编辑:我从REST服务器以hex和encryption格式得到响应,我尝试使用此代码,但我总是收到错误的参数错误。 你能帮我find错误吗? 是否有可能我首先将string响应转换为二进制格式? NSString *response = [request responseString]; NSData *encryptedData = [response dataUsingEncoding: NSASCIIStringEncoding]; NSString *key = @"32charlength"; NSString *iv = @"16charlength"; NSData *unencryptedData = NULL; size_t unencryptedLength = [unencryptedData length]; CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0, key, kCCKeySizeAES128, iv, [encryptedData bytes], [encryptedData length], unencryptedData, [encryptedData length], &unencryptedLength); […]

PHP iOS的AESencryption

我一直在尝试使用AESencryption在PHP和我的iOS应用程序之间进行通信。 到目前为止,我已经考虑了两种实现方法。 首先是使用OpenSSL。 在iOS方面,我以一种模仿这里显示的代码的方式实现: http : //saju.net.in/code/misc/openssl_aes.c.txt 。 在PHP方面,我把生成的密钥和IV(来自iPhone)并将其用作PHP opensslencryption的input。 结果在输出方面不同 我也考虑过: http : //iphonedevelopment.blogspot.com/2009/02/strong-encryption-for-cocoa-cocoa-touch.html 但是这个post: iOS和PHP之间的AESCrypt解密令我震惊 。 这个项目并不局限于AES,它似乎是一个强大的encryptionalgorithm,不会太难实施。 我的基本问题是:什么是最简单的方法来实现一个好的encryptionalgorithm,可以很容易地使用iOS和PHP之间的沟通?

iOSencryptionAES128 / CBC / nopadding为什么不能正常工作?

我有一个应用程序,需要使用AES / CBC /无填充编码一些数据。 该应用程序也在Android上移植。 那里的编码是这样做的: byte[] encodedKey = getKey(); SecretKeySpec skeySpec = new SecretKeySpec(encodedKey, "AES"); AlgorithmParameterSpec paramSpec = new IvParameterSpec(initializationVector); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, paramSpec); int blockSize = cipher.getBlockSize(); int diffSize = decrypted.length % blockSize; System.out.println("Cipher size: " + blockSize); System.out.println("Current size: " + decrypted.length); if (diffSize != 0) { diffSize = […]

在iOS中创build随机的128位AESencryption密钥

我想在ios中创build随机的AESencryption密钥(128位)。 我已经在search,但我找不到一个好的答案。 请给我一些build议。 提前致谢。 更新: 我已经使用BBAES库。 我使用下面的代码来生成encryption密钥,但是当我从NSData转换为NSString时,它显示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 = [[NSString alloc] initWithData:key encoding:NSUTF8StringEncoding]; }

Swift(iOS)和PHP中AES256encryption的结果不同

我在AES256工作,能够使用不安全的通道在iOS和PHP之间进行encryption/解密。 我看到很多类似的问题,围绕关键尺寸,模式(CBC或ECB),使用随机四等。但在这种情况下,我发现了一个奇怪的行为如下。 在这两种环境中configuration: – 密钥:32字节(256位) – 块大小:128位(标准) – iv:16字节(用于testing的静态) – 模式:CBC 如果我encryption一个16或32字节的文本(以匹配AES块大小),结果在Swift和PHP是相似的,但不完全相同: key =“12345678901234567890123456789012”plainText =“12345678901234567890123456789012”iv =“1234567890123456” Swift cipher = e5RnnlJkv4QGnGhkMwfvgMHr80NWUVhbvvfCdPQ5V2KyKJTx4KfWmn4HXi4dG0b8 PHP cipher = e5RnnlJkv4QGnGhkMwfvgMHr80NWUVhbvvfCdPQ5V2I = 如您所见,密码长度和PHP Base64string的最后两个字符有所不同。 但是,如果我使用不是AES128块大小乘数的文本,让我们说“Hello World”,则漫游器环境报告以下不同(但相同大小)的密码 Swift cipher = bdwO / 5C8a + pliIoIXtuzfA == PHP密码= oPotHCkxpOwQhIaCz6hNMw == 在这两种情况下(Swift和PHP),无论明文大小如何,密码都是正确解密的。 另外,Swift结果与代码的Objective-C版本一致 附上使用的简化代码: PHP $key = "12345678901234567890123456789012"; $iv = "1234567890123456"; $plaintext = "Hello World"; […]

使用SecKeyWrapperencryption16个字节的UTF8(ccStatus == -4304)

我使用Apple文档中的CryptoExercise示例代码中的Apple SecKeyWrapper类与AES128进行一些对称encryption。 出于某种原因,当我encryption1-15个字符或17个字符时,它会正确encryption和解​​密。 有16个字符,我可以encryption,但在解密时,会在CCCryptorFinal调用ccStatus == -4304之后引发exception,这表示解码错误。 (去搞清楚。) 据我所知,AES128使用每个encryption块16个字节,所以我得到这样的印象,即错误与明文长度落在块边界上有关。 有没有人遇到这个问题使用CommonCryptor或SecKeyWrapper ?