Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AES Encryption

Posted on 2014-02-01
12
Medium Priority
?
2,787 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 53

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Accepted Solution

by:
TheNautican earned 2000 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

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!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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