Detailed explanation of encryption and decryption function implemented by Java based on DES symmetric encryption algorithm

This paper describes the encryption and decryption function of Java based on DES symmetric encryption algorithm. Share with you for your reference, as follows:

Introduction to DES encryption related classes:

The securerandom class is inherited from Java util. Random class

There are three types of constructors for securerandom, and the following two are examples:

Securerandom () constructs a secure random number generator (RNG) that implements the default random number algorithm.

Secure random (byte [] seed) constructs a secure random number generator (RNG) that implements the default random number algorithm.

The deskeyspec class is used to generate the secret key content of the secret key using the original secret key

Deskeyspec has two constructors:

Deskeyspec (byte [] key) creates a deskeyspec object and uses the first 8 bytes in the key as the key content of the des key.

Deskeyspec (byte [] key, int offset) creates a deskeyspec object, and uses the first 8 bytes of the key starting from and containing offset as the key content of the des-ede key.

Secretkeyfactory, a key factory, is used to convert a key (an opaque encryption key of type key) into a key specification (a transparent representation of the underlying key material), and vice versa. A secret key factory only operates on secret (symmetric) keys.

The secret key object, the secret key object, generates the secret key by calling the generatesecret (deskeyspec deskeyspace) method of the secret key factory

Cipher class provides cryptographic functions for encryption and decryption, and obtains the instance by calling cipher's getInstance ("des")

The cipher object calls the init () method to initialize the object. The specific parameters of the init () method depend on the specific situation, including encryption and decryption constants

Finally, the doFinal () method of Cipher is used to encrypt and decrypt.

Here I would like to ask you a question, whether the first one uses base64encoder coding or the second one, org apache. commons. codec. binary. Base64 encoding requires UTF-8 / GBK encoding when converting string to byte and byte to string. Is it decoded?

1、 Sun misc. Base64decoder and base64encoder decode and encode

2、 Use org apache. commons. codec. binary. Base64 decodes and encodes

1、 Download address of rack package used in II: @ h_ 419_ 53@

Download: sun misc. BASE64Decoder 。 Download: Apache Base64 codec and decoder.

Password security online detection: @ h_ 419_ 53@http ://tools. jb51. net/password/my_ password_ safe

High strength password generator: @ h_ 419_ 53@http ://tools. jb51. net/password/CreateStrongPassword

Xunlei, express and whirlwind URL encryption / decryption tools: @ h_ 419_ 53@http ://tools. jb51. net/password/urlrethunder

Online hash / hash algorithm encryption tool: @ h_ 419_ 53@http ://tools. jb51. net/password/hash_ encrypt

Online MD5 / hash / SHA-1 / SHA-2 / SHA-256 / sha-512 / Sha-3 / ripemd-160 encryption tool: @ h_ 419_ 53@http ://tools. jb51. net/password/hash_ md5_ sha

Online SHA1 / sha224 / sha256 / sha384 / SHA512 encryption tool: @ h_ 419_ 53@http ://tools. jb51. net/password/sha_ encode

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>