I was a rookie ios, most recently in character encryption, I found a very strange question,
Other characters or strings that are returned to normal, except that only gyb return empty, as follows
+ (NSString *) DESSecret: (NSString *) plainText
{
NSString * ciphertext = nil;
NSData * textData = [plainText dataUsingEncoding: NSUTF8StringEncoding];
NSUInteger dataLength = [textData length];
unsigned char buffer [dataLength];
memset (buffer, 0, sizeof (char));
size_t numBytesEncrypted = 0;
NSRange range;
range.location = 0;
range.length = dataLength;
NSString * testString = key;
NSData * testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
Byte * testByte = (Byte *) [testData bytes];
CCCryptorStatus cryptStatus = CCCrypt (kCCEncrypt, kCCAlgorithmDES,
kCCOptionPKCS7Padding,
[Key UTF8String], kCCKeySizeDES,
testByte,
[TextData bytes], dataLength,
buffer, 1024,
& NumBytesEncrypted);
if (cryptStatus == kCCSuccess) {
ciphertext = [DESHandleString parseByte2HexString: buffer];
}
return ciphertext;
}
+ (NSString *) parseByte2HexString: (Byte *) bytes
{
NSMutableString * hexStr = [[NSMutableString alloc] init];
int i = 0;
if (bytes)
{
while (bytes [i]! = '\ 0')
{
NSString * hexByte = [NSString stringWithFormat: @ "% x", bytes [i] & 0xff] ;/ / / 16 decimal
if ([hexByte length] == 1)
[HexStr appendFormat: @ "0% @", hexByte];
else
[HexStr appendFormat: @ "% @", hexByte];
i + +;
}
}
NSLog (@ "bytes hexadecimal number is:% @", hexStr);
return hexStr;
}
Great God seek advice ah, I really do not understand ah
Reply:
How big God is no pointing ah
No comments:
Post a Comment