Page 1 of 1
Encryption DES
Posted: Wed Dec 06, 2006 11:42 pm
by sharmapankaj78
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi Friends,
I want to encrypt hash value of XML using DES. I tried with crypt () but this returns new value everytime. below is my code:
Code: Select all
$merReq = "<PAYGATE><MSG_CODE>AUTH</MSG_CODE><MER_URL>www.ycsindia.com/response</MER_URL>". "<MSG_HASH></MSG_HASH><TXN_DATE>12102006121010</TXN_DATE>". "<MER_CODE>ME0002</MER_CODE><ORDER_NO>1465625362</ORDER_NO>". "<TXN_AMT>1232390</TXN_AMT><TXN_CUR>INR</TXN_CUR></PAYGATE>";
$hash_key = strtoupper(sha1($merReq));
echo "<br>" . $hash_key;
$key = "ABCDABCDABCDABCD";
$crypt_key = crypt($hash_key, $key);
echo "<br>" . $crypt_key;
Please suggest, if there is any way to encrpt the hash value using DES.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Dec 07, 2006 12:13 am
by volka
take a look at
http://de2.php.net/mcrypt and the examples on the subsequent pages.
Posted: Thu Dec 07, 2006 12:27 am
by sharmapankaj78
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Thanks for yr reply. I have made use of mcrypt in this manner:
Code: Select all
$merReq = "<PAYGATE><MSG_CODE>AUTH</MSG_CODE><MER_URL>www.ycsindia.com/response</MER_URL>". "<MSG_HASH></MSG_HASH><TXN_DATE>12102006121010</TXN_DATE>". "<MER_CODE>ME0002</MER_CODE><ORDER_NO>1465625362</ORDER_NO>". "<TXN_AMT>1232390</TXN_AMT><TXN_CUR>INR</TXN_CUR></PAYGATE>";
$hash_key = strtoupper(sha1($merReq));
$key = "ABCDABCDABCDABCD";
$var1 = encrypt($key, $hash_key)
function encrypt($key, $plain_text) {
$plain_text = trim($plain_text);
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_DES,MCRYPT_MODE_CFB));
$c_t = mcrypt_cfb (MCRYPT_DES, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
return base64_encode($c_t);
}
The variable $var1 contains byte array. I want to convert it to the string and then calculate it's hex value. Please suggest!!!
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Dec 07, 2006 12:40 am
by volka
Sorry, i don't understand the question.
btw:
Posted: Thu Dec 07, 2006 1:02 am
by sharmapankaj78
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
After refering the page of mcrypt, i have re-defined by code in the following manner:
Code: Select all
$merReq = "<PAYGATE><MSG_CODE>AUTH</MSG_CODE><MER_URL>www.ycsindia.com/response</MER_URL>". "<MSG_HASH></MSG_HASH><TXN_DATE>12102006121010</TXN_DATE>". "<MER_CODE>ME0002</MER_CODE><ORDER_NO>1465625362</ORDER_NO>". "<TXN_AMT>1232390</TXN_AMT><TXN_CUR>INR</TXN_CUR></PAYGATE>";
$hash_key = strtoupper(sha1($merReq));
$key = "ABCDABCDABCDABCD";
$var1 = encrypt($key, $hash_key)
function encrypt($key, $plain_text)
{
$plain_text = trim($plain_text);
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_DES,MCRYPT_MODE_CFB));
$c_t = mcrypt_cfb (MCRYPT_DES, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
return base64_encode($c_t);
}
Above in the code, the variable $var1 contains encrypted data. I want to convert the encrypted data to the string and then calculate it's hex value. Please suggest!!!
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Dec 07, 2006 2:52 am
by volka
sharmapankaj78 wrote:After refering the page of mcrypt, i have re-defined by code in the following manner:

I dont see
any changes except
before:
sharmapankaj78 wrote:function encrypt($key, $plain_text) {
now:
sharmapankaj78 wrote:function encrypt($key, $plain_text)
{
And I still do not understand the question.
Code: Select all
$var1 = encrypt($key, $hash_key);
echo gettype($var1);
prints string. $var1 already contains a string. What's the hexvalue of a string?
Posted: Thu Dec 07, 2006 4:20 am
by sharmapankaj78
$hash_key = "FD30A380B84214497BB15B6266B55190C8DC1E5F";
I tried saverla methods to encrypt above mentioned hash key to get below mentioned encrypted value result. But unable to get this result.
The encrypted value should be:
9E901E502E92CF0CB431BDAFBB709078F8FF2C5C4A2F1817