Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2977
  • Last Modified:

AES Encryption

Hi

Anyone have code which will allow me to encrypt/decrypt a cell using AES 192/256 with CBC and SHA 192/256 key hashing algorithm?

Thank you
0
DemonForce
Asked:
DemonForce
1 Solution
 
Gareth GudgerCommented:
Hi DF,

Just checking with moderators to make sure we can help you with a decrypting question.
0
 
TheNauticanCommented:
There are two ways that I look at when attempting to do something outside of VBA built in functions. Either see if someone has already made a VBA module or see if I can gain the functionality through DLLs. Below are links on how to implement both solutions, but will require some tailoring on your part.

http://bytes.com/topic/access/insights/906850-aes-encryption-algorithm-vba-vbscript

social.msdn.microsoft.com/Forums/en-US/84d49593-2d8e-4e7c-af3a-61882af9557d/access-to-cryptencrypt-cryptoapiwinapi-functions-in-vba?forum=isvvba

Regards,
-Naut
0
 
Scott Fell, EE MVEDeveloperCommented:
>which will allow me to encrypt/decrypt a cell using AES 192/256 with CBC

There shouldn't be anything wrong with encrypting and decrypting a cipher like AES unless you are trying to crack somebody else's code of course.   If you are the one encrypting, then you should be able to decrypt as well because you have the key and salt.  which will allow me to encrypt/decrypt  This sounds like he is not trying to do anything wrong.  The links TheNautican supplied are only for AES.

SHA 192/256 on the other hand should not be able to be decrypted but used as a check.  I would answer something to the effect, the way to use SHA might be to send an encrypted pass code so the other side knows it is me.  sha("the_secret_word" & Date ).   On the other end, check to make sure the passcode is there.  

If data_sent = sha("the_secret_word" & Date ) then    'all is good

TheNautican only has links about AES and not how to use a dictionary to reverse engineer the sha hash.  It is good to know how things are done as a way to prevent though.


This is a great article on the subject http://arstechnica.com/security/2013/05/how-crackers-make-minced-meat-out-of-your-passwords/

https://crackstation.net/hashing-security.htm
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TheNauticanCommented:
Thanks for clearing that up guys. I was able to make a working sample using the following:
There are a few lines I use just for showing me what some values are. Make sure to add the CAPICOM reference library to use those constants. you can see them here if you want to see what they are defined as...

http://msdn.microsoft.com/en-us/library/windows/desktop/aa375675%28v=vs.85%29.aspx
One thing to keep in mind is that this library treats strings as unicode, so if you hash something and then try to verify it using another tool or get a hash that was generated from another tool be sure to use strConv(yourtstring, vbFromUnicode) first. That was the only way I could get mine to display results that matched an online hash tool i used for verification.


Sub Button1_Click()
    Set objEnc = CreateObject("CAPICOM.EncryptedData.1")
    Set objHash = CreateObject("CAPICOM.HashedData.1")
        
    objHash.Algorithm = CAPICOM_HASH_ALGORITHM_SHA_256
    strHashData = Range("A1")
    objHash.Hash strHashData
    strHash = objHash.Value
    Range("C2").Value = strHash
    
    objEnc.Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_AES
    objEnc.Algorithm.KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS
    objEnc.SetSecret strHash
    objEnc.Content = Range("B1")
    
    strEncrptedText = objEnc.Encrypt
    Range("C1").Value = strEncrptedText
    Range("C3").Value = "Hashed with: " & objHash.Algorithm
    Range("C4").Value = "Encrypted with: " & objEnc.Algorithm
    Range("C5").Value = "Key length: " & objEnc.Algorithm.KeyLength
    
End Sub
Sub Button2_Click()
    Set objDec = CreateObject("CAPICOM.EncryptedData.1")
    Set objHash = CreateObject("CAPICOM.HashedData.1")
    
    objHash.Algorithm = CAPICOM_HASH_ALGORITHM_SHA_256
    strHashData = Range("A1")
    objHash.Hash strHashData
    strHash = objHash.Value
    
    objDec.Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_AES
    objDec.Algorithm.KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS
    objDec.SetSecret strHash
    strText = Range("C1")
    objDec.Decrypt strText
    
    Range("D1").Value = objDec.Content

End Sub

Open in new window


Regards,
-Naut
0
 
DemonForceAuthor Commented:
Hi,

Thank you for your effort, however I can not find a capicom anything in my excel vba references?
0
 
DemonForceAuthor Commented:
Ok, found and installed and referenced capicom, but when code run it stops at very first line saying

Run-time error 429
ActiveX component can't create object
0
 
TheNauticanCommented:
DemonForce - I don't have my windows system but the version of office i use is 2010 and the version of CAPICOM is 2.1. The only other thing I did was make sure I selected the CAPICOM reference, but everything else was defaults.

-Naut
0
 
DemonForceAuthor Commented:
Yup, same as mine and its enabled in references too.
0
 
TheNauticanCommented:
one more thing came to mind, was the dll registered? from an admin prompt
regsvr32 capicom.dll
0
 
DemonForceAuthor Commented:
Yup
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now