2, DES encryption algorithm __ Encryption

Source: Internet
Author: User
Tags decrypt

Because of the illegal copying of computer software, communication leaks, data security is threatened, decryption and piracy problems increasingly serious, and even caused international disputes, so in information security technology, encryption technology occupies an irreplaceable position, so the information encryption technology and encryption means of research and development, by the national computer industry attention, Development with each passing day.

In the system research and development process, some data for the system or users, are very important and not leak, the important data encryption for any system is very necessary, such as the user's login password, trading password, etc., this article with user registration of the user password encryption, To roughly talk about some commonly used cryptographic algorithms and related implementations.

des encryption Algorithm

Des encryption algorithm is a block cipher, 64-bit for the packet data encryption, its key length is 56 bits, encryption and decryption with the same algorithm. Des encryption algorithm is the secret of the key, and the public algorithm, including encryption and decryption algorithm. In this way, only those who have mastered the same key as the sender can interpret the ciphertext data encrypted by the DES encryption algorithm.

The DES algorithm has three entry parameters: Key, Data, Mode. The key is 8 bytes A total of 64 bits, is the DES algorithm work key, data is also 8 byte 64 bits, is to be encrypted or decrypted, the mode for the work of DES, there are two kinds: encryption or decryption.

Des algorithm is such a work: such as mode for encryption, the key to the data to encrypt, generate the password form data (64-bit) as the output of DES, such as mode for decryption, the key to the form of the password data decryption, Revert to the plaintext form of data (64-bit) as the result of des output. At both ends of the communication network, the two sides agreed to the key, at the source point of communication with key to the core data des encryption, and then in the form of a password in the public communications network (such as telephone network) transmission to the end of the communication network, the data arrived at the destination, with the same key to decrypt the password data, It reproduces the core data in the form of plaintext. In this way, the security and reliability of core data (such as PIN, Mac, etc.) in the public communication network are ensured.

In Java, examples of using the DES algorithm are as follows:

public class Securitydesutils {private static Logger Logger = Logmanager.getlogger (Securitydesutils.class);
    private static final String encodeing = "UTF-8";
     Private static final String algorithm = "des";//Encryption Algorithm/** * @Comment des algorithm encryption * @param plaintext need encrypted text  * @param securekey length cannot be less than 8 * @Author Ron * @Date September 12, 2017 morning 11:54:12 * @return/public static
        String Encrypt (string plaintext, string securekey) {string encryptstr = "";
            try {byte[] DataSource = plaintext.getbytes (encodeing);
            SecureRandom random = new SecureRandom ();

            Deskeyspec Deskey = new Deskeyspec (securekey.getbytes (encodeing));
            Secretkeyfactory keyfactory = secretkeyfactory.getinstance (algorithm);

            Secretkey SecureKey = Keyfactory.generatesecret (Deskey);

            The Cipher object actually completes the cryptographic operation Cipher Cipher = cipher.getinstance (algorithm); Initializing a Cipher object CI with a secret keyPher.init (Cipher.encrypt_mode, SecureKey, Random);

            Now, get the data and encrypt//formally perform the cryptographic operation byte[] encryptsrc = Cipher.dofinal (DataSource);
        Encryptstr = base64utils.encodetostring (ENCRYPTSRC);
        catch (Exception e) {logger.error ("Des encrypted newspaper exception", e);
    return encryptstr; /** * @Comment decryption * @param encryptstr encrypted String * @param securekey length cannot be less than 8 * @Author Ron * 
     Date September 12, 2017 afternoon 1:12:56 * @return * @throws badpaddingexception * @throws illegalblocksizeexception 
        */public static string decrypt (string encryptstr, String securekey) {string decryptstr = "";
            try {byte[] src = base64utils.decodefromstring (encryptstr);
            The DES algorithm requires a trustworthy random number source securerandom random = new SecureRandom ();

            Create a Deskeyspec object Deskeyspec Deskey = new Deskeyspec (securekey.getbytes (encodeing));
   Create a key factory         Secretkeyfactory keyfactory = secretkeyfactory.getinstance (algorithm);
            Converts a Deskeyspec object to a Secretkey object Secretkey SecureKey = Keyfactory.generatesecret (Deskey);
            The Cipher object actually completes the decryption operation Cipher Cipher = cipher.getinstance (algorithm);
            Initialize the Cipher object with the key Cipher.init (Cipher.decrypt_mode, SecureKey, Random);
            Real start decryption operation byte[] decryptsrc = cipher.dofinal (src);
        Decryptstr = new String (decryptsrc,encodeing);
        catch (Exception e) {logger.error ("Des decryption failed", e);
    return decryptstr;
        public static void Main (string[] arg) throws exception{String src= "Ninhao";
        String srkey= "40c7f529c177487bb3b03cf16e962c82";
        String enstring = Encrypt (Src,srkey);

        SYSTEM.OUT.PRINTLN ("Encryption:" +enstring);
    System.out.println ("Decryption:" +decrypt (Enstring,srkey)); }
}

The main form of the

attack DES is called brute force or exhaustive, that is, repeatedly trying various keys until a match is reached. If DES uses a 56-bit key, the number of possible keys is 2, 56 times. With the development of computer systems, the security of DES is much weaker than it was when it first appeared, but it can be considered sufficient from the reality of non-critical nature. However, DES is now used only for authentication of old systems, and more for the new encryption standard-the Advanced Encryption Standard (Advanced encryption Standard,aes).

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.