Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6737921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:18:20+00:00 2026-05-26T11:18:20+00:00

I want to create an ASP.Net application with C# and I’ll store a data

  • 0

I want to create an ASP.Net application with C# and I’ll store a data on SQL server 2005, these data will be encrypted I want to find an algorithm to Encrypt a data with C# and decrypt it on SQL serve side and I want to Encrypt a some data with SQL and decrypt it with C# what is the best algorithm for this ??

private byte[] key = {
    0x61,
    0x72,
    0x84,
    0x7a,
    0x24,
    0x43,
    0x65,
    0x64,
    0x73,
    0x55,
    0x64,
    0x75,
    0x66

};



const string PASSWORD = "TestPassword";
public object Encrypt(string sPlainText)
{



    byte[] aPlainBytes = null;

    PasswordDeriveBytes aPassword = default(PasswordDeriveBytes);



    aPlainBytes = System.Text.Encoding.Unicode.GetBytes(sPlainText);

    aPassword = new PasswordDeriveBytes(PASSWORD, key);

    byte[] sEncryptedData = Encrypt(aPlainBytes, aPassword.GetBytes(32), aPassword.GetBytes(16));

    //' MessageBox.Show(Convert.ToString(sEncryptedData.ToString))

    return Convert.ToBase64String(sEncryptedData);



}



private byte[] Encrypt(byte[] sPlainData, byte[] aKey, byte[] aIV)
{



    MemoryStream oMemoryStream = new MemoryStream();



    Rijndael oRijndael = Rijndael.Create();

    oRijndael.Key = aKey;



    oRijndael.IV = aIV;



    CryptoStream oCryptoStream = new CryptoStream(oMemoryStream, oRijndael.CreateEncryptor(), CryptoStreamMode.Write);

    oCryptoStream.Write(sPlainData, 0, sPlainData.Length);

    oCryptoStream.Close();

    byte[] aEncryptedData = oMemoryStream.ToArray();




    return aEncryptedData;



}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:18:20+00:00Added an answer on May 26, 2026 at 11:18 am

    C#: System.Security.Cryptography

    SQL Server: Sql Server Encryption

    C# Example from here:

    private static void EncryptData(String inName, String outName, byte[] tdesKey, byte[] tdesIV)
    {    
        //Create the file streams to handle the input and output files.
        FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
        FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
        fout.SetLength(0);
    
        //Create variables to help with read and write.
        byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
        long rdlen = 0;              //This is the total number of bytes written.
        long totlen = fin.Length;    //This is the total length of the input file.
        int len;                     //This is the number of bytes to be written at a time.
    
        TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();          
        CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(tdesKey, tdesIV), CryptoStreamMode.Write);
    
        Console.WriteLine("Encrypting...");
    
        //Read from the input file, then encrypt and write to the output file.
        while(rdlen < totlen)
        {
            len = fin.Read(bin, 0, 100);
            encStream.Write(bin, 0, len);
            rdlen = rdlen + len;
            Console.WriteLine("{0} bytes processed", rdlen);
        }
    
        encStream.Close();                     
    }
    

    SQL Server Example from here:

    USE AdventureWorks2008R2;
    GO
    
    --If there is no master key, create one now. 
    IF NOT EXISTS 
        (SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)
        CREATE MASTER KEY ENCRYPTION BY 
        PASSWORD = '23987hxJKL969#ghf0%94467GRkjg5k3fd117r$$#1946kcj$n44nhdlj'
    GO
    
    CREATE CERTIFICATE HumanResources037
       WITH SUBJECT = 'Employee Social Security Numbers';
    GO
    
    CREATE SYMMETRIC KEY SSN_Key_01
        WITH ALGORITHM = AES_256
        ENCRYPTION BY CERTIFICATE HumanResources037;
    GO
    
    USE [AdventureWorks2008R2];
    GO
    
    -- Create a column in which to store the encrypted data.
    ALTER TABLE HumanResources.Employee
        ADD EncryptedNationalIDNumber varbinary(128); 
    GO
    
    -- Open the symmetric key with which to encrypt the data.
    OPEN SYMMETRIC KEY SSN_Key_01
       DECRYPTION BY CERTIFICATE HumanResources037;
    
    -- Encrypt the value in column NationalIDNumber with symmetric 
    -- key SSN_Key_01. Save the result in column EncryptedNationalIDNumber.
    UPDATE HumanResources.Employee
    SET EncryptedNationalIDNumber = EncryptByKey(Key_GUID('SSN_Key_01'), NationalIDNumber);
    GO
    
    -- Verify the encryption.
    -- First, open the symmetric key with which to decrypt the data.
    OPEN SYMMETRIC KEY SSN_Key_01
       DECRYPTION BY CERTIFICATE HumanResources037;
    GO
    
    -- Now list the original ID, the encrypted ID, and the 
    -- decrypted ciphertext. If the decryption worked, the original
    -- and the decrypted ID will match.
    SELECT NationalIDNumber, EncryptedNationalIDNumber 
        AS 'Encrypted ID Number',
        CONVERT(nvarchar, DecryptByKey(EncryptedNationalIDNumber)) 
        AS 'Decrypted ID Number'
        FROM HumanResources.Employee;
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to create a 3-Layer ASP.Net application (Presentation Layer, Business Layer, Data
I want to create a thread in a asp.net mvc application. What will happen?
I want to create a web service in ASP.NET that fetches data from a
I want to create a simple CMS for my asp.net-mvc site. Will I save
I want to programmatically create a directory on the server using ASP.NET. I have
I want to create a asp.net application which can show directions in a layout
am running the asp.net application...am enhancing the already developed project..i want to create the
I have a MVC, ASP.Net application and I want to create a dialog form.I
I use DotNetOpenAuth in my Asp.Net application. I want to create a login page
I will create an ASP.NET Web Application like this; Users can login their own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.