Solved

AES Encryption

Posted on 2014-02-01
12
2,369 Views
Last Modified: 2014-03-08
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
Comment
Question by:DemonForce
12 Comments
 
LVL 31

Expert Comment

by:Gareth Gudger
ID: 39826376
Hi DF,

Just checking with moderators to make sure we can help you with a decrypting question.
0
 
LVL 8

Expert Comment

by:TheNautican
ID: 39826653
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
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39831855
>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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 8

Accepted Solution

by:
TheNautican earned 500 total points
ID: 39833762
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
 

Author Comment

by:DemonForce
ID: 39834312
Hi,

Thank you for your effort, however I can not find a capicom anything in my excel vba references?
0
 

Author Comment

by:DemonForce
ID: 39834346
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
 
LVL 8

Expert Comment

by:TheNautican
ID: 39834389
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
 

Author Comment

by:DemonForce
ID: 39834392
Yup, same as mine and its enabled in references too.
0
 
LVL 8

Expert Comment

by:TheNautican
ID: 39834398
one more thing came to mind, was the dll registered? from an admin prompt
regsvr32 capicom.dll
0
 

Author Comment

by:DemonForce
ID: 39834948
Yup
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question