Home > Net >  RSA Encryption and Decryption using GUID
RSA Encryption and Decryption using GUID

Time:09-17

Can anyone help me in RSA Encryption and Decryption using public and private key

CodePudding user response:

RSA is an asymetric encryption algorithm. Which means that it requires a public and private key in order to encrypt and decrypt information. This would normally be done with randomly generated keys.

Is it technically possible to generate the RSA keys from passphrases, although that seems that's not really what you're looking for.

A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.

This may be used in a form of some popular symmetric encryption algorithms like AES to encrypt data with only 1 key, especially since the GUID is similar in length of a AES 128bit key. (Although actually using it may need some finagling since some cryptography algorithms require a certain pattern to be followed for their keys) Edit: I just tested it out, you can use a GUID as a 128bit AES Encryption key with no fancy stuff.

// create the string that we are going to encrypt
string original = "hello world";

// get a new GUID to use as an encryption key
Guid id =  Guid.NewGuid();

using (Aes myAes = Aes.Create())
{
    // make sure the key size matches what a GUID is (128 bits)
    myAes.KeySize = 128;

    // set the encryption key to use the GUID instead
    myAes.Key = id.ToByteArray();

    // Encrypt the string to an array of bytes.
    byte[] encrypted = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);

    // make sure bytes are encrypted
    Console.WriteLine(string.Join(", ", encrypted));

    // Decrypt the bytes to a string.
    string roundtrip = DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV);

    //Display the original data and the decrypted data.
    Console.WriteLine("Original:   {0}", original);
    Console.WriteLine("Round Trip: {0}", roundtrip);
}

All that being said, implementing effective encryption schemes for production and OPSEC environments is a serious endeavor that requires a lot of information, background, and a deep understanding of the current cryptography climate. I am neither well informed or educated enough to apine on proper encryption standards, techniques, and what is, and is not okay to use for effective encryption. Please complete your own individual research before implementing this code for serious projects.

  • Related