Solved

AES Encryption

Posted on 2014-02-01
12
2,121 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 30

Expert Comment

by:Gareth Gudger
Comment Utility
Hi DF,

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

Expert Comment

by:TheNautican
Comment Utility
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
Comment Utility
>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
 
LVL 8

Accepted Solution

by:
TheNautican earned 500 total points
Comment Utility
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
Comment Utility
Hi,

Thank you for your effort, however I can not find a capicom anything in my excel vba references?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:DemonForce
Comment Utility
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
Comment Utility
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
Comment Utility
Yup, same as mine and its enabled in references too.
0
 
LVL 8

Expert Comment

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

Author Comment

by:DemonForce
Comment Utility
Yup
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
excel file 5 44
Input box prompt to specify column letter using VBA 4 13
Excel 3 20
Populate data based on a  criteria 2 13
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now