首页
开发手册
应用中心
工具
用户中心
FoundPH Encrypted Handshake Protocol
English
中文简体
English
上一篇
下一篇
### FoundPHP Encrypted Handshake Protocol FoundPHP provides developers with encryption algorithms, including PHP's built-in can make users faster and more convenient to use, here is how we develop our own encryption scheme. #### Develop Encryption Library The handshake protocol generally follows the principle that it can be encrypted, but cannot be decrypted without a key, that is, there must be one or more sets of keys to encrypt characters in an unrecognizable way, so that even if the key is obtained, it cannot be used. The encryption algorithm needs to be implemented in a variety of programming languages, such as php and js, php and java, php and go, php and app, in order to achieve an effective handshake, otherwise it can only be called one-way encryption. The usual operation scheme: 1. Character encoding 2. Character replacement 3. Character encryption + sequence conversion 4. Compressed characters + encoding #### 1. Character Encoding Encode characters into a decodable code, such as base64, but because there is no key, all encrypted characters can be decrypted. At this time, one more encryption method can be used to set the outer layer of base64, which causes difficulty in decoding, which is usually easy to decode. #### 2. Character Replacement Also use base64 for encryption, but here replace multiple characters in base64 with characters you know. Remember that you cannot replace 1 character, but replace multiple letters, otherwise it will not be decoded. This is a large number There are rules that can be decoded under the data. #### 3. Character Encryption + Sequence Sonversion Here we also use base64 encryption, but we need to use cut characters to change the encoding order, usually there is a = symbol at the end of base64, we need to use `str_replace('=','FpEd',$base64);` to replace = with FpEd, after the replacement is completed, we obtain the length of the character, split the character into 2 parts, and replace the order. For example, encryption: FoundPHP Framework Buliding. Encryption result: Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLg== Encryption interference: We divide the encryption result `Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLgFpEdFpEd` into 2 parts `Rm91bmRQSFAgRnJhbWV3b3J` and `rIEJ1bGlkaW5nLgFpEdFpEd` At this time, we change the order to recombine the two characters, and add the length of character 2 before character 2, so that it is convenient to restore the data Encryption result: 23/rIEJ1bGlkaW5nLgFpEdFpEdRm91bmRQSFAgRnJhbWV3b3J At this time, base64_decode cannot be decrypted, and we need to know our algorithm to decrypt it. Examples are as follows:Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLgFpEdFpEd Length: 46 We divide the encryption result `Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLgFpEdFpEd` into 2 parts `Rm91bmRQSFAgRnJhbWV3b3J` and `rIEJ1bGlkaW5nLgFpEdFpEd` At this time, we change the order to recombine the two characters, and add the length of character 2 before character 2, so that it is convenient to restore the data Encryption result: 23/rIEJ1bGlkaW5nLgFpEdFpEdRm91bmRQSFAgRnJhbWV3b3J At this time, base64_decode cannot be decrypted, and we need to know our algorithm to decrypt it. Examples are as follows: ``` '; $str = str_replace('=','FpEd',$str); echo 'interference:'.$str.'
'; $len = strlen($str); echo 'length:'.$len.'
'; $leng = (int)$len/2; $str1 = substr($str,0,$leng); $str2 = substr($str,$leng); echo 'encryption1:'.$str1.'
'; echo 'encryption:'.$str2.'
'; $str = strlen($str2).'/'.$str2.$str1; echo 'encrypted result:'.$str.'
'; //decrypt data $decode = explode('/',$str); //length of str2 $str_llength of str2 = substr($decode['1'],0,$str_leng); $str1 = substr($decode['1'],$str_leng); echo 'decrypt1:'.$str1.'
'; echo 'decrypt2:'.$str2.'
'; //restore replaced characters $new_str = str_replace('FpEd','=',$str1.$str2); echo 'decoding:'.$new_str.'
'; echo 'decoding:'.base64_decode($new_str); ``` Get the decrypted result: ``` encryption:Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLg== interference:Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLgFpEdFpEd length:46 encryption1:Rm91bmRQSFAgRnJhbWV3b3J encryption2:rIEJ1bGlkaW5nLgFpEdFpEd encrypted result:23/rIEJ1bGlkaW5nLgFpEdFpEdRm91bmRQSFAgRnJhbWV3b3J decrypt1:Rm91bmRQSFAgRnJhbWV3b3J decrypt2:rIEJ1bGlkaW5nLgFpEdFpEd decoding:Rm91bmRQSFAgRnJhbWV3b3JrIEJ1bGlkaW5nLg== decrypt:FoundPHP Framework Buliding. ``` #### 4. Compressed Character + Encoding This is a more complicated method, and it needs to call the gz compression method to combine and encrypt the code, compress and re-encode (the secret key cooperates with the code to make the code difficult to decode) The method is more complicated and you can study it yourself.