Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of encryption and decryption examples of PHP and Java des

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report