SSCrypto to PHP
SSCrypto to PHP
- Subject: SSCrypto to PHP
- From: Walter Johnson <email@hidden>
- Date: Mon, 8 Sep 2008 15:14:53 -0400
Greetings,
I need help with encrypting data to send to a php script to be
decrypted. I stumbled across the SSCrypto framework and I've been
using it to encrypt and decrypt a simple NSString. However, when I
attempt to plug this into my php script, it only outputs gibberish.
Can someone give me a hand here and perhaps guide me?
Here's the cocoa code:
-------------------------
NSString * secretMessage = @"Hello World!";
NSString * secretKey = MY_BF_KEY;
NSLog(@"secretMessage: %@", secretMessage);
NSLog(@"secretKey: %@", secretKey);
NSData *seedData1 = [secretKey
dataUsingEncoding:NSUTF8StringEncoding];
SSCrypto * crypto = [[SSCrypto alloc]
initWithSymmetricKey:seedData1];
NSArray *ciphers = [NSArray arrayWithObjects:@"bf-cbc", nil];
NSString *password = secretMessage;
[crypto setClearTextWithString:password];
int n;
for(n = 0; n < [ciphers count]; n++)
{
NSData *cipherText = [crypto encrypt:[ciphers objectAtIndex:n]];
NSString *cipherString = [crypto cipherTextAsString];
NSData *clearText = [crypto decrypt:[ciphers objectAtIndex:n]];
NSLog(@"Original password: %@", password);
NSLog(@"Cipher text: '%@' using %@", [cipherText
encodeBase64WithNewlines:NO], [ciphers objectAtIndex:n]);
NSLog(@"Cipher text as hex: '%@' using %@", [cipherText hexval],
[ciphers objectAtIndex:n]);
NSLog(@"Cipher string: '%@'", cipherString);
NSLog(@"Clear text: '%s' using %@", [clearText bytes], [ciphers
objectAtIndex:n]);
NSLog(@" ");
}
-------------------------
and the output
-------------------------
2008-09-08 14:25:50.925 tybit-blowfish[2588:10b] secretMessage: Hello
World!
2008-09-08 14:25:50.927 tybit-blowfish[2588:10b] secretKey: pass
2008-09-08 14:25:50.929 tybit-blowfish[2588:10b] Original password:
Hello World!
2008-09-08 14:25:50.930 tybit-blowfish[2588:10b] Cipher text:
'nUYw6WbDs0M7NjXB6q6r2g==' using bf-cbc
2008-09-08 14:25:50.930 tybit-blowfish[2588:10b] Cipher text as hex:
'9d4630e966c3b3433b3635c1eaaeabda' using bf-cbc
2008-09-08 14:25:50.932 tybit-blowfish[2588:10b] Cipher string:
'ùF0Èf√≥C;65¡ÍÆ´⁄'
2008-09-08 14:25:50.932 tybit-blowfish[2588:10b] Clear text: 'Hello
World!' using bf-cbc
-------------------------
Now, I take the cipherText encoded as Base64 (the line right below
'Original password') and plug it into my base-64/blowfish decoder in
PHP.
-------------------------
-------------------------
I know the base64 encode/decode is working properly because I can
successfully send and interpret data that is only base64 encoded. But
I want to add another layer of encryption to further secure the data.
Base64 is really only serving to allow the encoded string transport
over http.
I can also vouch that the php code can successfully decrypt a
message encrypted with blowfish. I have similar code in another
script which reads encrypted data from a hex string delivered from a
windows application. So my concern is why won't it work with
SSCrypto/openssl? Any help will be much appreciated.
-------------------------
Message sent via tyBit Mail - http://www.tyBitMail.com/
Search the Entire Web From Your Desktop!
tyBit™ Unified Search™
Download your FREE copy today!
www.tyBit.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden