473,466 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with "AES Encryption Algorithm for VBA and VBScript"

zmbd
5,501 Recognized Expert Moderator Expert
Re: AES Encryption Algorithm for VBA and VBScript.

Hello,
Trying to step thru this code...

After reading thru the code, I tried to compile it

The following errors occur in the VBA module:
- "Set oFile1 = oFS.OpenTextFile(sFile, ForReading)" I get the error "ForReading" isn't a defined variable.
- "expandedKey = expandKey(aesKey, sbox, rcon)" as an undefined sub/function.

The first error I was able to work around using "OPEN" etc...
The second error, I'm not entirely sure about how to fix.

-z
May 14 '12 #1

✓ answered by Rabbit

Glad you got it working. I tested against a handful of NIST values but I wasn't exhaustive in my tests. Let me know if you find any errors.

Just be aware that my code was more optimized for speed than for readability. So rather than encapsulating the transformations in their own function, I expanded everything and put most of it in one function to avoid the overhead.

6 9814
NeoPa
32,556 Recognized Expert Moderator MVP
When I look at the first block of code I see that expandKey() is defined on line #387.
Expand|Select|Wrap|Line Numbers
  1. Function expandKey(ByRef key(), ByRef box(), ByRef rcon())
Maybe you had a problem copying it all completely.

ForReading is a constant with a value of 1. ForWriting is a constant with a value of 2. See more at TechNet - Reading and Writing Text Files. If these constants aren't already defined for you then I suspect you may not have all the correct references set. Alternatively, you can set them up yourself or use the literal values.
May 14 '12 #2
zmbd
5,501 Recognized Expert Moderator Expert
THANK YOU!!!

I'd never used this method to open a textfile for output.
In the past I'd used "Freefile", "Open", "Print", and "Close."
After reading up on the code I found where the references were missing from the "ForReading" "ForWriting", even found a bit of example code; however, the "ForAppend" was set to 3 not 8 which burggered me for awhile.

I'll try that cut and paste again!
I've been working from a textbook to create an AES function in VBA and here it is!!!!!!!!!

SO COOL!

-z

PS:
NeoPa:
Went back to the code... this is what I see when the the code is expanded:


Also, for some reason... all I see from the code you posted is the function header... no code.

What am I doing wrong?

-z
Attached Images
File Type: jpg AES_Code_PrtScn.jpg (22.6 KB, 4524 views)
May 14 '12 #3
Rabbit
12,516 Recognized Expert Moderator MVP
zmbd, NeoPa only posted the header to show that the function was indeed defined in the code. What he was saying is that if you're getting the error, perhaps something went wrong when you copied and pasted the code from the site.
May 14 '12 #4
NeoPa
32,556 Recognized Expert Moderator MVP
@zmbd
Your picture is of the code at the bottom of the second block of code. My reference was to the first block ;-)
NeoPa:
When I look at the first block of code I see that expandKey() is defined on line #387.
May 14 '12 #5
zmbd
5,501 Recognized Expert Moderator Expert
Rabbit,
1ST - Thank You for the code!!

Indeed the function is in the ECM-Code-Block; however, I had originally copied the code from the following CBC-Code-Block.

Thus, to have something to work thru, I copied the code from the ECM-Code-Block, made a few tweeks:
- added "()" in the DIM sections for array variables;
- changed a "ByVal" to "ByRef" as required for array;
- added CONST for "forwrite" and "forread";
- change oWP.Value to sPass for the passphrase and added an "sPassIn" to the call (figured oWP is a textbox on a form which is what I would do))

After that the VBA compiler was happy and the code ran as expected.

So I started comparing the ECM-Mode code to the posted CBC code... some of the same tweeks as above needed to be made for the CBC code to compile and I had to C&P the expandkey() from the ECM code into the copied CBC code. It now will compile and encyphr the selected text file.

I haven't looked thru the expandkey() nor used the NIST files to verify.

Once again,
Thank You Rabbit!

I had finished creating the arrays and started trying to understand how to implement the equations... the text I am using is heavy on the theory and not so much on the practical application, and then, WOW, your code showed up! What a help in trying to follow the textbook!

-Z
May 14 '12 #6
Rabbit
12,516 Recognized Expert Moderator MVP
Glad you got it working. I tested against a handful of NIST values but I wasn't exhaustive in my tests. Let me know if you find any errors.

Just be aware that my code was more optimized for speed than for readability. So rather than encapsulating the transformations in their own function, I expanded everything and put most of it in one function to avoid the overhead.
May 14 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
4
by: Kinsley Turner | last post by:
Hey-ho, I'm getting a bit out of my depth porting the 'tiny encryption algorithm' from C to python. Ref: http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm...
15
by: Optimus | last post by:
I would like to know if there is a encryption algorithm that returns only lowercase encrypted string. Thanks in advance.
3
by: Dave Cullen | last post by:
Hello C I have a project that requires a calculated "key" to be used in a security access application. The customer supplies a secret 8 byte number that gets combined with the serial number of...
2
by: thiyagu | last post by:
In our company for internal security compliance we need to encrypt the data to/from DB server; What is the encryption algorithm used by DB2 & what key lengths are supported in DB2 LUW v8 & v9 when...
9
Rabbit
by: Rabbit | last post by:
Introduction The Advanced Encryption Standard is the algorithm that won the National Insitute of Standards and Technology's (NIST) search for a standardized encryption algorithm in 2001. In 2002, it...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.