QT's encryption algorithm

Source: Internet
Author: User

Before writing this article, I have pondered over whether the term encryption is accurate and, more strictly, password hashing-converting data (such as Chinese and English letters, special characters) through complex algorithms to another fixed-length value.  Qcryptographichash classIn Qt, Qcryptographichashclass provides the code that generates the password hash .Method. This class can be used to generate cryptographic hash values for binary or text data. Currently supportsMD4, MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512. This class is in QtCore4.3.was introduced. Public Type
    • Enum algorithm {Md4, MD5, SHA1, Sha224, ..., sha3_512}
  Public Methods
    • Qcryptographichash (Algorithm method)
    • ~qcryptographichash ()
    • void AddData (const char * data, int length)
    • BOOL AddData (Qiodevice * device)
    • void AddData (const Qbytearray & Data)
    • void Reset ()
    • Qbytearray result () const
static public member
    • Qbytearray Hash (const Qbytearray & Data, algorithm method)
member Type document
    • Enum Qcryptographichash::algorithm
Constant Take value Describe
Qcryptographichash::md4 0 Generate a MD4 hash
Qcryptographichash::md5 1 Generate a MD5 hash
Qcryptographichash::sha1 2 Generate a SHA-1 hash
qcryptographichash::sha224 3 Generates a SHA-224 hash (SHA-2). Introduction in Qt5.0
qcryptographichash::sha256 4 Generates a SHA-256 hash (SHA-2). Introduction in Qt5.0
qcryptographichash::sha384 5 Generates a SHA-384 hash (SHA-2). Introduction in Qt5.0
qcryptographichash::sha512 6 Generates a SHA-512 hash (SHA-2). Introduction in Qt5.0
qcryptographichash::sha3_224 7 Generates a sha3-224 hash. Introduction in Qt5.1
qcryptographichash::sha3_256 8 Generates a sha3-256 hash. Introduction in Qt5.1
qcryptographichash::sha3_384 9 Generates a sha3-384 hash. Introduction in Qt5.1
qcryptographichash::sha3_512 10 Generates a sha3-512 hash. Introduction in Qt5.1
member function Documentation
    • Qcryptographichash::qcryptographichash (Algorithm method)
Constructs an object that can create data as a cryptographic hash value.
    • Qcryptographichash::~qcryptographichash ()
Destroys the object.
    • void Qcryptographichash::adddata (const char * data, int length)
The cryptographic hash of the first-length character data.
    • BOOL Qcryptographichash::adddata (Qiodevice * device)
Reads the data from the open input until it ends and hashes it. Returns True if the read is successful. This feature is introduced in QtCore5.0.
    • void Qcryptographichash::adddata (const Qbytearray & Data)
The overloaded adddata () of this function.
    • Qbytearray Qcryptographichash::hash (const Qbytearray & Data, algorithm method) [static]
Use this method to return hash data.
    • void Qcryptographichash::reset ()
Resets the object.
    • Qbytearray Qcryptographichash::result () const
Returns the last hash value. For example (the text is "password" string encryption): (1) the static Hase () method to calculate the Qbytearray Byte_array;
Byte_array.append ("password");
Qbytearray Hash_byte_array = Qcryptographichash::hash (Byte_array, QCRYPTOGRAPHICHASH::MD5);
QString MD5 = Hash_byte_array.tohex ();
(2) Calculating Qbytearray Byte_array by result () method;
Byte_array.append ("password");
Qcryptographichash hash (QCRYPTOGRAPHICHASH::MD5);
Hash.adddata (Byte_array); Add data to encrypted hash value
Qbytearray Result_byte_array = Hash.result (); Returns the final hash value
QString MD5 = Result_byte_array.tohex ();
MD5 result: 5f4dcc3b5aa765d61d8327deb882cf99, can go to find the corresponding tool to verify! Recommend a website: http://www.md5.com.cn/.
The effect is as follows:
As shown above, whether using the exhaustive method or other means to crack, is sufficient to demonstrate that there is no absolute security. Because it is theoretically possible to crack any kind of ciphertext by finding a match, the problem is only to shorten the time.
comparison between MD5 and SHA-1Both are exported by MD4, so SHA-1 and MD5 are very similar. Their strength and other characteristics are similar, but there are several differences: (1) Security against strong attacks: the most significant and important difference is that the SHA-1 digest is 32 bits longer than the MD5. Using the brute force technique, generating any message to make its digest equal to the difficulty of a given digest is MD5 to 2^128 order of magnitude, whereas to SHA-1 is a 2^160 order of magnitude operation. In this way, SHA-1 has a greater advantage over strong attacks.
(2) Security of password Analysis: Because of the MD5 design, vulnerable to password analysis attacks, by contrast, SHA-1 is not.
(3) Speed: On the same hardware, SHA-1 run slower than MD5. Collision:Because the hash function produces a fixed length of ciphertext, the result is a finite set. The plaintext to be processed can be any information transmitted by the computer network. In other words, the plaintext information is an infinite set, the ciphertext information is limited, there is no one-to-one correspondence between the two sets.    There are always a number of different plaintext occurrences of the same cipher, which is called collisions. MD5 and SHA-1 were considered to be safe enough hash algorithms, as early as 1994 reported that the most computationally capable machines, an average of 24 days can find a MD5 collision. Professor Xiao's approach has been possible to find MD5 and SHA-1 collisions within a short period of time. Even so, it does not mean that two methods are ineffective, and that they can be further dealt with by their own means. For example: With MD5 and Sha. A for MD5 processing to get B, a in the SHA processing to get C, and then B and C (for example: add), can also be combined with the results of MD5 encryption. This is enough to reduce the impact machine to very small and very small, so there is no absolute safety, only more secure.

QT Encryption Algorithm

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.