Click here to Skip to main content
15,503,491 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
How to encypt and decrypt a integer value in linq and store it in varbinary(max) in sql please tell me

<pre> public string GetQCAsync(string UserLimit)
        {
            var DSet1 = _context.test.Where(x => x.Uid == 1).FirstOrDefault();

            var provider = new System.Security.Cryptography.RSACryptoServiceProvider();
            provider.ImportParameters(your_rsa_key);

            DSet1.NoOfUsers = provider.Encrypt(
                System.Text.Encoding.UTF8.GetBytes(UserLimit), true);

            string decryptedTest = System.Text.Encoding.UTF8.GetString(
                provider.Decrypt(DSet1.NoOfUsers, true));

            return decryptedTest;
        }


this is what i tried
what is
your_rsa_key
in here

What I have tried:

public string GetQCAsync(string UserLimit)
       {
           var DSet1 = _context.test.Where(x => x.Uid == 1).FirstOrDefault();

           var provider = new System.Security.Cryptography.RSACryptoServiceProvider();
           provider.ImportParameters(options);

           DSet1.NoOfUsers = provider.Encrypt(
               System.Text.Encoding.UTF8.GetBytes(UserLimit), true);

           string decryptedTest = System.Text.Encoding.UTF8.GetString(
               provider.Decrypt(DSet1.NoOfUsers, true));

           return decryptedTest;
       }
Posted
Updated 11-Jan-22 18:05pm
v3
Comments
Maciej Los 12-Jan-22 14:52pm    
Sounds like an answer....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900