Solved

AES Encryption

Posted on 2014-02-01
12
2,433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

730 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