ios - iOS中的3des加解密
<p><p>我正在研究 3DES 加密和解密。我已成功完成加密。对于解密,我正在使用此代码,但没有得到准确的结果。我的加密字符串是“<strong>CHc3TsfJgYs=</strong>”, key 是“<strong>meristem</strong>”。请告诉我我做错了什么?</p>
<pre><code> NSString *token = @"CHc3TsfJgYs=";
NSString *key = @"meristem";
const void *vplainText;
size_t plainTextBufferSize;
plainTextBufferSize = ;
vplainText = (const void *) ;
CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t movedBytes ;
bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);
// memset((void *) iv, 0x0, (size_t) sizeof(iv));
NSString *initVec = @"init Vec";
const void *vkey = (const void *) ;
const void *vinitVec = (const void *) ;
ccStatus = CCCrypt(kCCDecrypt,
kCCAlgorithm3DES,
kCCOptionPKCS7Padding | kCCOptionECBMode,
vkey, //"123456789012345678901234", //key
kCCKeySizeDES,
NULL,// vinitVec, //"init Vec", //iv,
vplainText, //"Your Name", //plainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);
NSString *result;
NSData *myData = ;
result = ;
// result = ;
NSLog(@"dis is data %@",result);
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>ccStatus = CCCrypt(kCCDecrypt,
kCCAlgorithm3DES,
kCCOptionPKCS7Padding | kCCOptionECBMode,
vkey, //"123456789012345678901234", //key
kCCKeySize3DES,
NULL,// vinitVec, //"init Vec", //iv,
vplainText, //"Your Name", //plainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);
</code></pre>
<p>你需要改变 <code>kCCKeySizeDES</code> -> <code>kCCKeySize3DES</code></p></p>
<p style="font-size: 20px;">关于ios - iOS中的3des加解密,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/21454774/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/21454774/
</a>
</p>
页:
[1]