I am encrypting the data with blowfish CBC mode in C using openssl.
I am trying to decrypt the data with the key using PHP mycrypt.But it does not give me the actual data but some garbage text.I am able to decrypt and encrypt with mcrypt but if i encrypt with c i am unable to decrypt with PHP.
16 6948 Atli 5,058
Expert 4TB
Hey.
Not much we can do for you without seeing your code, I'm afraid.
Oh certainly..
I am using command line ssl to encrypt file using blowfish CBC mode.
The decryption code is using mcrypt. -
<?php
-
//base 64 decoding the encrypted data.
-
$data = base64_decode('BdRY7DN8iPDdjdsevowiZQ==');
-
$key ='12345678';
-
$iv ='1234';
-
-
$res2 = mcrypt_decrypt(MCRYPT_BLOWFISH,$key,$data,MCRYPT_MODE_CBC,$iv);
-
echo $res2;
-
?>
-
Regards
akaash
Any ideas?
regards
akaash
Atli 5,058
Expert 4TB
I can't see anything wrong with that, unless: - Your $key or $iv are incorrect.
- You input data is invalid
- Your C code is doing something wrong. - Which, honestly, is a lot more likely than your PHP code being wrong.
- ... Nope, that's all I've got.
One thing, though. Why do you decrypt the data as Base64 before sending it to Mcrypt?
hi,,thanks for the input.
I am doing base64 decode because data that i get as encrypted is garbage type.doing base64 helps to make it easy to send.
Regards
sumit
Hello friends.I have been trying to encrypt data in C and decrypt in PHP.SO far no success.:(
I want to know if any of you have done encryption in C and PHP.
If yes,please let me know and how.
I encrypt data in c and when in decrypt in php,i get vague characters.
Regards
akaash
Are you sure you are using the same encryption algorithim. If you encrypt something in C and write the encrypted text to a plain old text file, then you should be able to take that to any platform and decrypt it.
If you encrypted file that you encrypted in C will not decrypt using PHP then I would blame the user not the technology.
I do agree that but cross platform encryption has much more that just key and iv like padding,file format etc .
I want to know where i am missing those details and are there more to be counted.I guess person who has done this in php and C is the best judge.
regards all
akaash
does it say that mcrypt_decrypt needs a $data value that has been base64_decoded?
That would be my first suspicion.
NO.no such error..in fact i the first letter of the block is visible.
say i encrypt text HeloheloHelohelo, I am able to get the first and 9th letter and rest is garbage text. It is able to decrypt the first byte of the block.
regards
I would think that the first and 9th letter appearing as if they are decrypted is just a coincidence.
BF encoded string = 'oYmlOpvn9335KhBzpB2ISh/CefMkAglV6YCPQzYhlXk='
secret key = "\xe2\xa4\xa5\x99(&\xa6\x105\x11\x89\xa7\xb7>&\x9a \xc4\xea\xd2\xbcLM\xb0\x91'Z\x84\xe4@\x05\xf3\xb5"
Code used to encrypt the string: -
define Encode(c,s):
-
base64.b64encode(c.encrypt(pad(s)))
-
-
define pad(s):
-
s+(BLOCK_SIZE - length(s) % BLOCK_SIZE)*PADDING
-
-
define BLOCK_SIZE as 32 and PADDING as character '}'
-
Method call examples: -
pad("test")
-
>>> 'test}}}}}}}}}}}}}}}}}}}}}}}}}}}}'
-
-
CipherObj = create new Blowfish object with argument (secret)
-
>>> CipherObj = Blowfish object at 0x92f0430
-
-
encodedString = Encode(CipherObj, "some BF encrypted text")
-
>>> encodedString = 'oYmlOpvn9335KhBzpB2ISh/CefMkAglV6YCPQzYhlXk='
-
Now take my encodedString and secretkey and decrypt it using blowfish. See if you get "some BF encrypted text".
This was encrypted using python, but if anyone is interested in doing it in any other language post your code here.
Are you referring to the problem indicated in this message at http://php.net/manual/en/book.mcrypt.php?
When using 3DES between PHP and C#, it is to be noted that there are subtle differences that if not strictly observed, will result in annoying problem encrypt/decrypt data.
1), When using a 16 bytes key, php and c# generates total different outcome string. it seems that a 24 bytes key is required for php and c# to work alike.
2), php doesnt have a "padding" option, while c# has 3 (?). My work around is to add nulls i.e. chr(0) to the end of the source string to make its size times of 8, while in c#, PaddingMode.Zeros is required.
3) the key size has to be times of 8, in php, to make it work for c#.
Try using a 24 byte encryption key.
jkmyong, how is this relevant?
TripleDES =/= Blowfish
Oops. Would like to delete the post.
Anyways, OP please post the c code you're using for encryption. Maybe the problem is in the encryption.
Hello friends,
Thanks a lot for your response and interest.
I tried encrypting with the command line of ssl.While decrypting with php it threw error.Then i created functions to encrypt with c using EVP functions and it worked well.Just some issue like padding came which can be managed.
if you want the C code i can post that too.
Thanks to all
Akaash
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Oliver Spiesshofer |
last post by:
Hi,
I am trying to load the LDAP and the MCrypt module under WinXP and PHP
Version 4.3.7.
The strange thing is that I have several other modules that work just fine:
extension=php_bz2.dll...
|
by: Dica |
last post by:
i've used the sample code from msdn to create an encyption/decryption
assembly as found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp
i'm...
|
by: Y Store Tools |
last post by:
I've just started playing with mcrypt for encryption but not sure if
I'll need to write my own. Basically I don't need anything advanced
for protection but want to mask the data so it's not easily...
|
by: Chris Fink |
last post by:
I have walked through all of the WSE 3 Hands on Labs and got everything
working fine. When I create my own certificate and install it in the stores,
my client application that is consuming my WSE...
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4. Using code from this newsgroup, I have a decrypt
function, trying to decrypt data (encryped using a corresponding mcrypt
function). What am I doing wrong? These are...
|
by: =?Utf-8?B?RGFuTQ==?= |
last post by:
Can someone help with the following problem. I am sending an encrypted SOAP
message to a .NET 2.0 + WSE 3.0 web service. When .NET attempts to decrypt
the message it cannot read the private key...
|
by: =?UTF-8?Q?Ahmad_=E3=8B=A1_Baitalmal?= |
last post by:
Hi,
I'm having a hard time getting python-mcrypt extension to build.
I installed libmcrypt with --prefix=/usr and I checked that the
library exists
-rwxr-xr-x 1 root wheel 352K Sep 19...
|
by: Elliot |
last post by:
When decrypt the xml, output "Unable to retrieve the decryption key."
Can anyone help me solve the problem?
I got the code from http://msdn.microsoft.com/en-us/library/ms229746.aspx
using...
|
by: FarooqRafiq |
last post by:
Hi,
My requirement is that a string is encrypted in VB.NET and sent to PHP, PHP decrypts the string (till here the logic is working) and then the PHP should encrtyp (where i am having problems)...
|
by: simon2x1 |
last post by:
how can i decrypt password with i encryted with md5 i try using mcrypt it did not work
<?PHP
$sql = "SELECT password FROM user WHERE email='$email_to'";
$result = mysql_query($sql);
$rows =...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |