Cryptographic algorithms-md5, RSA, DES

Source: Internet
Author: User
Tags decrypt md5 encryption

Recently because to do a cryptographic function, a simple understanding of the encryption algorithm, now more commonly used there are three encryption algorithm MD5 encryption algorithm, RSA encryption algorithm, DES encryption algorithm.


MD5 encryption algorithm

Definition: The MD5 algorithm transforms any length of "byte string" into a large integer of 128bit, and it is an irreversible string transform algorithm, even if you see the source program and algorithm description, you cannot change the value of MD5 back to the original string.

Application: In some operating systems, the user's password is saved in MD5 way, when the user logs in, the system bar user entered the password calculated into MD5, and then compared with the MD5 values saved in the database, if the same login success, if different, the login fails, and the system does not know what the user's password.


RSA Encryption algorithm

Definition: RSA can be used for both data encryption and digital signatures.

Principle: 1, find out three number p, Q, R p, q is a different medium prime, R is the number with (P-1) (q-1) coprime,p, Q, r these three numbers are private key

                2, find  m,  make  rm = 1 mod  (p-1) (q-1) calculate  N = PQ   m, n  These two numbers are  public key 

           3, A is the data to be encrypted,  b = a^m mod n,  (0 <= b < n), B is the data after encryption

           4,   decryption Process a = b^r mod pq  (0&NBSP;<=&NBSP;C&NBSP;<&NBSP;PQ)

Limitations: Due to the large number of calculations, the speed has been a drawback of RSA. Generally, only a small amount of data encryption is used.


des encryption algorithm

A bit:the security of the Des cryptography should not depend on the secrecy of the algorithm, and its security is only based on the secrecy of the encryption key (dynamically generated key)

Principle:des algorithm has three parameters: Key, Data, Mode. Where key is 8 bytes A total of 64 bits, is the working key of the DES algorithm, the data is 8 bytes 64 bits, is to be encrypted or decrypted, the mode for DES works, there are two kinds: encryption or decryption. If mode is encrypted, the data is encrypted with key to generate the password form (64 bits) as the output of the DES, and if mode is decrypted, it uses key to decrypt the data in the form of the password. The plaintext (64-bit) reverts to data as the output of DES.

    applications: We finally use DES encryption algorithm, but because the user's confidentiality to the data is not a high requirement, So instead of using dynamic key, we used a static key.

Encryption Program

            Dim des as New System.Security.Cryptography.DESCryptoServiceProvider ' des algorithm            Dim inputbytearray As Byte ()            Inputbytearray = System.Text.Encoding.Default.GetBytes (sourcestr)            des. Key = System.Text.Encoding.UTF8.GetBytes (MyKey) ' MyKey des with 8 characters, tripledes to 24 characters            DES.IV = System.Text.Encoding.UTF8.GetBytes (Myiv) ' Myiv des with 8 characters, tripledes to 24 characters            Dim MS as New System.IO.MemoryStream            Dim CS as New System.Security.Cryptography.CryptoStream (MS, Des. CreateEncryptor (), System.Security.Cryp            tography. CryptoStreamMode.Write)            Dim SW as New System.IO.StreamWriter (CS)            SW. Write (SOURCESTR)            SW. Flush ()            cs. FlushFinalBlock ()            Ms. Flush ()            encryptdes = convert.tobase64string (ms. GetBuffer (), 0, Ms. Length)


called  

Edes = Encryptdes (Datadata (j, K). Value, "12345678", "ABCDEFGH")

Decrypt

<span style= "FONT-SIZE:18PX;" ><strong>        Dim des as New System.Security.Cryptography.DESCryptoServiceProvider ' des algorithm        des. Key = System.Text.Encoding.UTF8.GetBytes (MyKey) ' MyKey des with 8 characters, tripledes to 24 characters        DES.IV = System.Text.Encoding.UTF8.GetBytes (Myiv) ' Myiv des with 8 characters, tripledes to 24 characters        Dim buffer as Byte () = Convert.frombase64string (SOURCESTR)        Dim ms As New System.IO.MemoryStream (buffer)        Dim cs As New System.Security.Cryptography.CryptoStream (MS, Des. CreateDecryptor (), System.Security.Cryptography.CryptoStreamMode.Read)        Dim sr as New System.IO.StreamReader (CS)        decryptdes = Sr. ReadToEnd () </strong></span>


called

<span style= "FONT-SIZE:18PX;" ><strong>        Userentity.userid = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (0), "12345678", "ABCDEFGH")        Userentity.username = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (1), "12345678", "ABCDEFGH")        Userentity.password = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (2), "12345678", "ABCDEFGH")        Userentity.realyname = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (3), "12345678", "ABCDEFGH")        Userentity.phonenumber = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (4), "12345678", "ABCDEFGH")        Userentity.unitname = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (5), "12345678", "ABCDEFGH")        Userentity.unittype = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (6), "12345678", "ABCDEFGH")        Userentity.isdelete = Decryptdes (myDataSet. Tables (0). Rows (Count). Item (7), "12345678", "ABCDEFGH") </strong></span>


Here, we are just a simple understanding of these three algorithms, these three algorithms involved in a lot of content, there is no place to ask Daniel to treatise.


Cryptographic algorithms-md5, RSA, DES

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.