Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Analysis of encryption and decryption examples of PHP and Java des

Shulou Source: shulou.com Published: 2022-05-31 10:35:38 09月11日 Update

Most people do not understand the knowledge points of this article "encryption and decryption case Analysis of PHP and Java des", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "encryption and decryption case analysis of PHP and Java des" article.

Des encryption is one of the most widely used encryption methods in the Internet. Php supports des encryption through the mcrypt extension library. To use des encryption in Php, you need to install the mcrypt extension library first.

The following is an example of encryption and decryption

The copy code is as follows:

$iv_size = mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB)

$iv = mcrypt_create_iv ($iv_size, MCRYPT_RAND)

$key = "This is a very secret key"; / / key

$text = "Meet me at 11 o'clock behind the monument."; / / content to be encrypted

Echo ($text). "\ n"

$crypttext = base64_encode (mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv))

Echo $crypttext. "\ n"; / / encrypted content

Echo mcrypt_decrypt (MCRYPT_RIJNDAEL_256,$key,base64_decode ($crypttext), MCRYPT_MODE_ECB,$iv); / / decrypted content

MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_192 and MCRYPT_RIJNDAEL_256 are usually used in AES encryption algorithms. The following 128,192,256 represent the number of bit of the secret key (that is, encrypted Key). For example, if MCRYPT_RIJNDAEL_128 is used, then the secret key length is 128bit when encrypted with this algorithm, for example, $key = 'fjjda0& 9 ^ $# + *% $fada', is 20 characters. In the actual encryption, only the first 16 characters are used for encryption (1608128), which will be filled with'\ 0' in the php that is less than 128bit.

Sometimes when you do project docking, you may use Php encryption, while the other party is written in java. In the process of interfacing, it is found that the encrypted content cannot be decrypted by the other party. This is because there is a difference between Php and java in implementing this algorithm. In order to encrypt and decrypt correctly, both sides need to do some processing:

PHP:

The copy code is as follows:

Tags: Encryption content code encryption and decryption examples time case analysis analysis algorithms characters each other that is articles knowledge articles symmetry that is the Internet representative value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Microsoft MySQL MariaDB