DES encryption, des encryption algorithm

Source: Internet
Author: User

DES encryption, des encryption algorithm

Encryption is classified into symmetric encryption and asymmetric encryption. Asymmetric encryption uses different keys for encryption and decryption, such as RSA. symmetric encryption uses the same key for encryption and decryption, such as DES. Although asymmetric encryption is more secure, the computing process is complex and time-consuming. It is generally used only for key information (such as account and password). For non-key information, symmetric encryption is generally used, such as DES.

The full name of DES is Data Encryption Standard, which is the Data Encryption Standard. No matter what the plaintext is, the encrypted ciphertext is a string consisting of 16 characters (0-f.

The encryption code is as follows:

    private static byte[] encrypt(byte[] data, byte[] key) throws Exception {        SecureRandom sr = new SecureRandom();        DESKeySpec dks = new DESKeySpec(key);        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);        SecretKey securekey = keyFactory.generateSecret(dks);        Cipher cipher = Cipher.getInstance(ALGORITHM);        cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);        return cipher.doFinal(data);    }

The main code for decryption is as follows:

    private static byte[] decrypt(byte[] data, byte[] key) throws Exception {        SecureRandom sr = new SecureRandom();        DESKeySpec dks = new DESKeySpec(key);        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);        SecretKey securekey = keyFactory.generateSecret(dks);        Cipher cipher = Cipher.getInstance(ALGORITHM);        cipher.init(Cipher.DECRYPT_MODE, securekey, sr);        return cipher.doFinal(data);    }

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.