Key scenarios of Enterprise Library encryption application blocks

Source: Internet
Author: User
ArticleDirectory
    • Encrypt data with symmetric providers
This topic describes the application Program Most common cases that must be addressed when the encryption function is provided in. Each scenario explains tasks, describes the real-world situations that may occur in tasks, and describes how to use encrypted application blocks to complete tasks. Code . The scenario is as follows:

    • Encryption secrets. This scenario demonstrates how to use symmetricAlgorithmProvides Program Encryption secrets.
    • Decrypt the secret. This scenario demonstrates how to use the symmetric algorithm provider to decrypt encrypted secrets.
    • Obtain the text hash. This scenario demonstrates how to generate hash values from data.
    • Verify that the hash value matches certain texts. This scenario demonstrates how to compare plain text data with previous hash values generated from the data to verify that the data has not been changed since the initial hash is generated.

Encrypt data with symmetric providers

A common encryption task uses symmetric providers to encrypt data. This task may be performed when the application has confidential data.

Typical goals

In this scenario, symmetric providers are used to encrypt the provided data. The output of the symmetric provider is encrypted data.

Solution

Call the appropriate overload (string or byte array) of the cryptographer class's static encryptsymmetric access request to specify the name of the symmetric provider to be used and the data to be encrypted.

Quick Start

For examples of how to use the encryptsymmetric method to encrypt data, see roaming: encryption secrets.

Use encryptsymmetric

The following code uses the encryptequalric method to encrypt data in the string format. This overload returns a base64 encoded string.

C #
 
String encryptedcontentsbase64 = cryptographer. encryptpolicric ("symatrix rovider", "password ");
Visual Basic
 
Dim encryptedcontentsbase64 as string
Encryptedcontentsbase64 = cryptographer. encryptpolicric ("symatrix rovider", "password ")

The following code uses the encryptequalric method to encrypt data in the byte array. This overload returns a byte array.

C #
Byte [] valuetoencrypt = encoding. Unicode. getbytes ("password ");
Byte [] encryptedcontents = cryptographer. encryptsymmetric ("symatrix rovider", valuetoencrypt );

// Clear the byte array memory that holds the password.
Array. Clear (valuetoencrypt, 0, valuetoencrypt. Length );
Visual Basic
 
Dim valuetoencrypt = encoding. Unicode. getbytes ("password ")
Dim encryptedcontents as byte () = cryptographer. encryptsymmetric ("symatrix rovider", valuetoencrypt)

'Clear the byte array memory that holds the password.
Array. Clear (valuetoencrypt, 0, valuetoencrypt. length)

Usage tips

When encrypting data, consider the following:

    • Make sure that the appropriate symmetric provider is configured in the Enterprise Library configuration console.
    • Sensitive data is cleared from memory as quickly as possible. Leaving unencrypted data in the memory poses a security threat to the data. It should be noted that the data in the memory may also be stored on the hard disk, because the operating system will write the data into a swap file. If the computer crashes, the operating system saves the content in memory to the disk.

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.