- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在程序中进行AES加密和解密。解密时我无法获取纯文本。我的代码如下...
- (NSData *)aesEncrypt:(NSString *)key data:(NSData *)data
{
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) // fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [data length];
//See the doc: For block ciphers, the output size will always be less than or equal to the input size plus the size of one block. //That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
kCCAlgorithmAES128,
kCCOptionPKCS7Padding,
keyPtr, kCCKeySizeAES256,
NULL /* initialization vector (optional) */,
[data bytes],
dataLength, /* input */
buffer, bufferSize, /* output */ &
numBytesEncrypted);
if (cryptStatus == kCCSuccess)
{
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
free(buffer); //free the buffer;
return nil;
}
- (NSData *)aesDecrypt:(NSString *)key data:(NSData *)data
{
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) // fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [data length];
//See the doc: For block ciphers, the output size will always be less than or equal to the input size plus the size of one block. //That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
kCCAlgorithmAES128,
kCCOptionPKCS7Padding,
keyPtr,
kCCKeySizeAES256,
NULL /* initialization vector (optional) */,
[data bytes],
dataLength, /* input */
buffer,
bufferSize, /* output */
&numBytesEncrypted);
if (cryptStatus == kCCSuccess)
{
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
free(buffer); //free the buffer;
return nil;
}
最佳答案
加密或解密数据时的 key 必须相同。你是如何调用解密方法的,你能分享一下代码吗?
关于iphone - AES 解密不起作用,请帮忙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7480677/
根据https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query处的文档要执行空闲/忙碌查询,您必须在正
我在启动 Apache 后使用 XAMPP 1.7.7 我收到此警报: Busy... Apache started [Port 80] 我已经打开了 httpd.conf 文件,并将端口号更改为 8
我有端口问题。 每当我启动 Apache 时,它都会给我这个错误: Busy - Apache Started [port 80] 当我启动 Mysql 时出现以下错误: Busy - ERROR
当我运行我的代码时,我总是得到后台工作人员很忙。有帮助吗? struct FtpSetting { public string Server { get; set
在我们的 Android 和 iOS MVVMCross 应用程序中,我们偶尔会遇到 SQLiteException: busy 异常。 给定下面的代码,我们有几个存储库,每个存储库都构造一个下面的实
每次运行解决方案(20 projs)时,我都会收到此错误。我尝试禁用 UI 选项、resharper、删除未使用的扩展等,但仍然无法通过此错误。 我使用的是 VS 2015 Update 2 Ente
我正在使用这个插件 https://github.com/mozilla/rust-android-gradle ,这需要我添加 tasks.whenTaskAdded { task -> i
我是一名优秀的程序员,十分优秀!