troubleshooting Question

.NET AES Encryption

Avatar of ggreen79
ggreen79 asked on
.NET ProgrammingMicrosoft Development
3 Comments1 Solution2240 ViewsLast Modified:
I'm trying to use the code below to encrypt a string.

Please provide valid keyLength, stringKey and IV to make this code work.
protected string EncryptIt(string text)
        byte[] key = { };
        byte[] IV = {  };
        string stringKey = "";
	int keyLength = 0;
	key = Encoding.UTF8.GetBytes(stringKey.Substring(0, keyLength));
	AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
        Byte[] byteArray = Encoding.UTF8.GetBytes(text);
        MemoryStream memoryStream = new MemoryStream();
        CryptoStream cryptoStream = new CryptoStream(memoryStream, aes.CreateEncryptor(key, IV), CryptoStreamMode.Write);
	CryptoStream.Write(byteArray, 0, byteArray.Length);
        return Convert.ToBase64String(memoryStream.ToArray());
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros