C# Encryption | GitLocker.com Product

C# Encryption

Last updated:

0 purchases

C# Encryption Image
C# Encryption Images
C# Encryption Images
C# Encryption Images

$5.00

Languages

C#

Categories

C#
Add to Cart

Description:

This C# code demonstrates various cryptographic techniques, including hashing and both symmetric (AES) and asymmetric (RSA) encryption. It utilizes the .NET framework's cryptographic libraries to securely hash data and encrypt/decrypt messages.

Key Components

  1. SHA-512 Hashing:
    • The CreateSHA512Hash method generates a SHA-512 hash of a given string input using the SHA512 class from the System.Security.Cryptography namespace.
    • The resulting hash is converted to a hexadecimal string format for easy readability using BitConverter.
  2. AES Encryption and Decryption:
    • The AesEncryptionDecryption method generates a random 256-bit AES key and an initialization vector (IV) using the Aes class.
    • It encrypts the input data using AES in CBC mode. The method creates a CryptoStream to handle the encryption process.
    • The function returns the encrypted data encoded in base64 format, along with the base64-encoded AES key and IV.
  3. RSA Encryption and Decryption:
    • The RsaEncryptionDecryption method generates a pair of RSA keys (public and private) using the RSA class.
    • It encrypts the input data with the public key using OAEP padding with SHA-512 for enhanced security.
    • The function returns the encrypted data in base64 format and the private key exported as a base64-encoded string.
  4. Main Method:
    • The Main method demonstrates the usage of the above functions.
    • It hashes a sample string ("Hello, World!") using SHA-512 and prints the result.
    • It encrypts a secret message ("Secret Message") using AES and prints the encrypted data, AES key, and IV.
    • It also encrypts the same message using RSA and prints the encrypted data along with the private key.

Example Output

When executed, the program will produce output similar to the following:

javascript

 

SHA-512 Hash: <hashed_value>
Encrypted data (AES): <base64_encoded_encrypted_data>
AES Key: <base64_encoded_aes_key>
AES IV: <base64_encoded_iv>
Encrypted data (RSA): <base64_encoded_encrypted_data>
Private Key (Base64): <base64_encoded_private_key>

This output demonstrates the successful execution of hashing and encryption processes, showcasing the functionality of the cryptographic techniques implemented.

Conclusion

This C# code effectively illustrates the use of cryptographic methods for securing data through hashing and encryption. It provides a clear example of how to implement SHA-512 hashing, AES symmetric encryption, and RSA asymmetric encryption using the .NET cryptographic libraries. This code serves as a valuable reference for understanding basic cryptographic operations in C#.

Features:

  1. SHA-512 Hashing:
    • The CreateSHA512Hash method generates a SHA-512 hash of a given string input using the SHA512 class from the System.Security.Cryptography namespace.
    • The resulting hash is converted to a hexadecimal string format for easy readability using BitConverter.
  2. AES Encryption and Decryption:
    • The AesEncryptionDecryption method generates a random 256-bit AES key and an initialization vector (IV) using the Aes class.
    • It encrypts the input data using AES in CBC mode. The method creates a CryptoStream to handle the encryption process.
    • The function returns the encrypted data encoded in base64 format, along with the base64-encoded AES key and IV.
  3. RSA Encryption and Decryption:
    • The RsaEncryptionDecryption method generates a pair of RSA keys (public and private) using the RSA class.
    • It encrypts the input data with the public key using OAEP padding with SHA-512 for enhanced security.
    • The function returns the encrypted data in base64 format and the private key exported as a base64-encoded string.
  4. Main Method:
    • The Main method demonstrates the usage of the above functions.
    • It hashes a sample string ("Hello, World!") using SHA-512 and prints the result.
    • It encrypts a secret message ("Secret Message") using AES and prints the encrypted data, AES key, and IV.
    • It also encrypts the same message using RSA and prints the encrypted data along with the private key.

Requirements:

  • .NET Framework
  • .NET SDK

Instructions:

For best results, use the latest version of Visual Studio Community. 

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product: (if this is empty don't purchase this product)

Customer Reviews

There are no reviews.