Paip. PHP implements cross-platform cross-language encryption and decryption

Source: Internet
Author: User
& Nbsp; paip. to implement cross-platform encryption and decryption in PHP, parameters must be transmitted between ASP and PHP system modules. for convenience, DES encryption is directly prepared without MD5 signatures .. However, DES in ASP and PHP cannot be encrypted with each other... What CBC mode and IV vector are there. A lot of data. I still can't adjust it for a long time. forget it. write your own encryption method .. The main method of password encryption is to replace and shift .. In addition, I want to use paip. PHP to implement cross-platform cross-language encryption and decryption.

Parameters must be transmitted between ASP and PHP system modules. for convenience, you can directly use DES

.. However, DES in ASP and PHP cannot be encrypted with each other... What CBC mode and IV vector are there. I

For a long time, it still won't work. forget it. write your own encryption method ..

The main method of password encryption is to replace and shift .. In addition,

My requirements are,
1. you need to use the key.
2. the algorithm is simple and can be easily rewritten in another language .. The DES algorithm is a big problem, MD, and difficult to use.

PASS... Although the effect is good, it is a bit complicated and difficult to rewrite ..
3. algorithms can be freely combined based on the strength. to enhance the encryption effect, multiple flip algorithms can be used. here, to make it simple, just

I flipped it all...
4. you can use multiple keys, which greatly enhances the effect without losing to DES or 3DES.
5. encrypt non-ASCII characters: do not encrypt them directly .. You can convert BASE64 and URLENCODE to an ASCII string before proceeding.

Encryption may be Deng ..

Here, I have conceived the idea of encryption and encryption:

1. first reverse the string
2. cyclically add strings and KEY groups
3. the added result is converted into hexadecimal characters .. It is mainly used to save some space ..
4. the returned result is OK...
5. the decryption process can be reversed ..

PHP call demonstration:
$ Key = "iluvnjyn ";
Echo atiDecode ("D7D5E2DACF", $ key); the decryption result "admin" is displayed"

ASP encryption demo:
Key_L71723 = "iluvnjyn"
Msg = "admin"
Newstr = atiEncode (msg, key_L71723) // Generate the encryption result "D7D5E2DACF"

--------------------------- PHP source code ------------------

// Decryption method
Function atiDecode ($ msg, $ key ){

$ Key_L71723 = $ key;
$ Key_L71723 = $ key_L71723. $ key_L71723;
$ Key_L71723 = $ key_L71723. $ key_L71723;
$ Key_L71723 = $ key_L71723. $ key_L71723 ;;
$ Key_L71723 = $ key_L71723. $ key_L71723 ;;

// $ Msgarr = explode ("-", $ msg); // split
$ Msgarr = str_split ($ msg, 2 );
$ Keyarr = str_split ($ key_L71723 );
$ Newstr = "";

For ($ I = 0; $ I <count ($ msgarr); $ I ++ ){
$ V = $ msgarr [$ I];
$ CharInt = hexdec ($ v); // 'encode char
$ Keychar = $ keyarr [$ I];
$ Newchar = chr ($ charInt-ord ($ keychar ));

$ Newstr = $ newstr. $ newchar;
}
$ Newstr = strrev ($ newstr );
// 'Newstr = base64Encode (newstr)
Return $ newstr;
}

--------------- Source code of ASP encryption method
Function atiEncode (msg, key)

Msg = back_str (msg) 'reverse the string
Dim key_L71723
Key_L71723 = key
Key_L71723 = key_L71723 + key_L71723
Key_L71723 = key_L71723 + key_L71723
Key_L71723 = key_L71723 + key_L71723
Dim msgarr
Msgarr = str2array (msg)
Dim keyarr
Keyarr = str2array (key_L71723)
Dim newstr
Newstr = ""
'And the KEY group are added cyclically
For I = 0 to ubound (msgarr)
Dim char
Char = msgarr (I)
Dim newchar 'Int format
Newchar = asc (char) + asc (keyarr (I ))
Newchar = hex (newchar)

Newstr = newstr + cstr (newchar)
Next

AtiEncode = newstr
End function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.