Thursday 15 August 2013

objective c - aes 256 encryption on PHP and decryption with ios pannding -


I am trying to encrypt the stars on my server and sending it to my iPhone.

When I'm encrypting on my iPhone and it has been sent to a decryption on my server, everything is fine.

But when I'm trying to encrypt my server ( php page ) I can not decrypt it on my iPhone.

Example: When I encrypt "true" on my PHP, I am getting:

ca 82 66 c 8 ho 5a a 9fb d 8 7f 25 B6 1f 0fb68 54 72 75 65 0 0 0 0 0 0 0 0 0 0 0

Then I am doing something - Base 64

yoJmyL5aqfvYfyW2HvD7aA == When IM is sending to my iPhone then I can not decrypt it correctly ..

But when I encrypt "true" on my iPhone I am trying:

ca 82 66 c8 ho 5 a 9fb d 8 7f25b6 1fffb 68 54 72 75 65 cccccccccccc

base64 -

fwqkKsopev3Xmu4BF4OE5Q ==

Can someone do me a Direct to the solution?

The difference is the padding PHP solution does not have a standardized padding mechanism. Instead, it uses zero-padding, which ends with a string of plaintext bytes with plain text as trim > Or right_trim method for that matter).

You should read the pad in the PDP before encryption, just like the CCC crypt. Ckapet uses a good standardized padding mode called PKCS # 7 padding. This mode is always the same as the number of pad 1 to 16 (blowsize) bytes byte, the number of padding bytes. In your example this is hexadecimals in 0C h, or 12 padding bytes.

How to PAD / Unpad in PHP Padding / unpadding is always done on raw plain text, never on ciphertext.

Note that your ciphertext has probably been fixed with IV values ​​already. These first 16 bytes should not be decrypted. They should be used as the fourth and omitted by decrypt functions. Normally a new IV value must be created for each encryption. Otherwise, you will be able to see if the beginning of the plain text is like the first one. Random IV changes the whole cipher text for each encryption.

No comments:

Post a Comment