We help IT Professionals succeed at work.

AES-256 Encryption in c#

165 Views
Last Modified: 2019-02-13
Hello,
I need an AES-256 encryption/decryption example and found one.  How would I know if this is 256 bit encryption?

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=netframework-4.7.2

Thank  you!
Comment
Watch Question

David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Easy way to do this is to either call out to the openssl command line tool or use an openssl library binding.

If you call out to the openssl command line tool, your code will tend to work better across openssl releases, as a variety of errors seem to keep cropping up in c# bindings calling openssl libraries directly.

Author

Commented:
Thank you David Favor,
I don't understand what you are saying.

Thank you!
Devin BeckerIdentity Management and Security
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
Radha,

On the page you linked, after the example, it says that the parameter KeySize can be assigned a Key Size, which will allow you to choose between 64, 128, or 256 Key Length. This is not show in the example, but it is possible.

EDIT: it looks like the KeySize is in bytes. which means you would uses a KeySize of 32bytes if you wanted 256Bit encryption.

Hope this helps,

Devin Becker
DevOps Associate @ EE

Author

Commented:
Thank you Devin.  Do you have any example or sample code to show me?  Thank you!
Devin BeckerIdentity Management and Security
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
Radha,

Along with the link you had already posted, here is this information: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aesmanaged.keysize?view=netframework-4.7.2#System_Security_Cryptography_AesManaged_KeySize

EDIT: Also worth noting the difference between bytes and bits. 1 Byte = a combination of 8 bits. 8 bits = 1 byte. 32 bytes = 256 bits. Keep this in mind when writing out your code.

Hope this helps,

Devin Becker
DevOps Associate @ EE
Senior .Net Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hello Kyle,
I was looking at a another thread where it is defined like this.

                  CCEncryption.m_Key = new byte[0x20];
                  CCEncryption.m_IV = new byte[0x10];

Any idea what does it mean?  What are the variables m_Key and m_IV?   Why are they declared byte[0x20] and byte[0x10]?

I know these are stupid questions.  But, I did not understand.

Thank you!

Author

Commented:
Thank you guys for your help.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.