ios 7中的解密不能使用aes [英] decrytption in ios 7 not working using aes

查看:179
本文介绍了ios 7中的解密不能使用aes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在从xml获取数据,它被加密,我需要解密收到的nsstring,

  UserName = @QEjbHvzPjk + YuLDVPUJuEA ==; 

我需要将这个nsstring解密为常规格式,我搜索并找到aes,但不进行任何更改,

  NSString * msg = [FBEncryptorAES decryptBase64String:UserName 
keyString:@01234567890abcdefghijklmnopqrstuvwxyz];

if(msg)
{
UserName = msg;

NSLog(@解密:%@,msg);
} else
{
UserName = @(解密失败);
}

如何解密上述的nsstring,谢谢Advance。

解决方案

字符串不仅是AES加密的,它是Base64编码的。尾随的==是base64填充的典型值。 AES加密也产生数据字节,而不是ASCII字符,输出是块大小的倍数。 Base64对加密结果进行编码通常是ASCII码,可以包含在XML中。



对于iOS 7,NSData有几种Base64 API方法。可能你想要的是:

   - (id)initWithBase64EncodedString:(NSString *)base64String选项:(NSDataBase64DecodingOptions)选项

示例:

  NSString * userName = @QEjbHvzPjk + YuLDVPUJuEA ==; 
NSData * data = [[NSData alloc] initWithBase64EncodedString:userName选项:0];
NSLog(@data:%@,data);

NSLog输出:

data:< 4048db1e fccf8e4f 98b8b0d5 3d426e10> p>

数据可能是AES加密的,它是块长度的倍数,如果是,您将需要密钥以及填充,模式和可能的iv。



请注意, FBEncryptorAES 类方法 encryptedBase64String 接受Base64输入,解密密钥串是可疑的,并且由于方法和可能,加密可能与该解密方法不匹配iv。所以 FBEncryptorAES 类可能不是你需要的。


In My App, i'm getting data from xml, where it is encrypted, and i need to decrypt the received nsstring,

 UserName = @"QEjbHvzPjk+YuLDVPUJuEA==";

I Need to decrypt this nsstring into regular format, i searched and find aes , but it doesn't make any changes,

  NSString* msg = [FBEncryptorAES decryptBase64String:UserName
                                          keyString:@"01234567890abcdefghijklmnopqrstuvwxyz"];

if (msg)
{
    UserName = msg;

    NSLog(@"decrypted: %@", msg);
} else
{
    UserName = @"(failed to decrypt)";
}

How can i decrypt the above nsstring, Thanks in Advance.

解决方案

The string is not only AES encrypted, it is Base64 encoded. The trailing "==" is typical of base64 padding. Also AES encryption produces data bytes, not ASCII characters and the output is a multiple of the block size. It is common to Base64 encode the result of encryption so it is ASCII and can be included in XML.

For iOS 7 there are several Base64 API methods for NSData. Probably what you want is:

- (id)initWithBase64EncodedString:(NSString *)base64String options:(NSDataBase64DecodingOptions)options

Example:

NSString *userName = @"QEjbHvzPjk+YuLDVPUJuEA==";
NSData *data = [[NSData alloc] initWithBase64EncodedString:userName options:0];
NSLog(@"data: %@", data);

NSLog output:
data: <4048db1e fccf8e4f 98b8b0d5 3d426e10>

The data probably is AES encrypted, it is a multiple of block length, and if so you will need the key and also information on padding, mode and possibly iv.

Note that the FBEncryptorAES class method encryptedBase64String does accept Base64 input but the decryption key string is suspect and the encryption may not match this decryption method due to method and possible iv. So the FBEncryptorAES class may not be what you need.

这篇关于ios 7中的解密不能使用aes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆