From block ciphers to file encryption.

Source: Internet
Author: User

There are already many block cipher, such as 3DES, blowfish, and AES...

The encryption algorithm provides how to convert the key and plaintext to obtain ciphertext.

Starting from the encryption algorithm, there is still a way to get an available program for encrypting files. The main problems are:

1. From a file to plaintext, the file size is usually not the size of a block. So, how to block the file, how to deal with different blocks, what if it cannot be divided into complete blocks?

2. From password (passphrase or passphrase) to key, the user's encryption and decryption password is usually a string, such as "fotally". How can I get a key from the password?

RSA labs standard PKCS #5, gives some recommended practices, see http://www.rsa.com/rsalabs/node.asp? Id = 2127.

The solution is as follows:

I. File partitioning, filling, and encryption Modes

It is easy to block files by Cipher Block Size.

The choice of encryption mode is very important, including ECB, CBC, ofB, counter, and so on. See http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation

OfB and counter modes are actually converting block cipher into stream cipher, so padding is unnecessary.

For common CBC modes, padding is inevitable. If there is no special reason, the filling mode of PKCS #5 is generally used.

For more information about fill mode, see http://en.wikipedia.org/wiki/Padding_ (cryptography) and http://www.di-mgt.com.au/cryptopad.html

2. Get the key from the password

The key obtained from the password method is called key derivation function, PKCS #5 recommended password-based key derivation function is pbkdf2 (http://en.wikipedia.org/wiki/PBKDF2), the basic idea is to hash the password to get the key, there are two key points

1, salt, not explained

2. Key stretching repeats the hash several times (over 1,000 times ). In normal application scenarios, getting a key from a password is a one-time operation. Increasing complexity does not affect the application, this will greatly increase the competitor's computing complexity. In short, this is a way to increase security from the engineering perspective.

For more information about KDF, see Logging.

For file encryption, you can usually use the CBC mode, but the ECB mode certainly does not work. Bruce Schneider also recommends the CBC mode in applied cryptography. Because padding is required, the encrypted ciphertext file is larger than the plaintext file, and a block may be added at most (for AES, this is bits, that is, 16 bytes ).

As mentioned in the above article, the counter mode is recommended in Schneider's new book. I have not confirmed it, but the advantages of the counter mode are obvious (random access is allowed ).


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.