Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i have key.dat file which is the key .i am unable to encrypt the below string to the output:H6ckSNuLNI6esReMTNEHeQ==
if i use nsbundle to read key.dat file i am getting only first two characters that is ¨Ì

Please solve my problem

string:60266203

key: ¨Ìsrjava.security.KeyRepΩ˘O≥àö•CL	algorithmtLjava/lang/String;[encodedt[BLformatq~LtypetLjava/security/KeyRep$Type;xptDESur[B¨Û¯T‡xp«ÜX^§ÕÔtRAW~rjava.security.KeyRep$Typexrjava.lang.EnumxptSECRET

out put: H6ckSNuLNI6esReMTNEHeQ==
I want full code.Please solve anybody my question
Posted

1 solution

 
Share this answer
 
Comments
Member 10907890 5-Aug-14 4:01am    
i used the same code but i am getting out put as IQnSTMrZfHk=
this is the code i used
- (void)viewDidLoad
{
[super viewDidLoad];


key = [[NSBundle mainBundle] pathForResource:@"key"
ofType:@".dat"];
key= [NSString stringWithContentsOfFile:key encoding:NSASCIIStringEncoding error:nil];
;
NSString *encrypted =[self doCipher:@"60266203"];

}

- (NSString*) doCipher:(NSString*)encryptValue {

const void *vplainText;
size_t plainTextBufferSize = [encryptValue length];
vplainText = (const void *) [encryptValue UTF8String];
CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t movedBytes = 0;

bufferPtrSize = (plainTextBufferSize + kCCBlockSizeDES) & ~(kCCBlockSizeDES - 1);
bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);

Byte iv [] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};


const void *vkey = (const void *) [key UTF8String];

ccStatus = CCCrypt(kCCEncrypt,
kCCAlgorithmDES,
kCCOptionECBMode,
vkey,
kCCKeySizeDES,
iv,
vplainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);

NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];
NSString *result = [myData base64EncodedStringWithOptions:0];

return result;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900