susam / aes.vbs Goto Github PK
View Code? Open in Web Editor NEWAES-256-CBC Encrypt and Decrypt Functions in VBScript
License: MIT License
AES-256-CBC Encrypt and Decrypt Functions in VBScript
License: MIT License
The line Set aes = CreateObject ("System.Security.Cryptography.RijndaelManaged") gives the following error
(null): 0x80131509
I run this command to check class. Everything is regular.
powershell -Command [System.Reflection.Assembly] :: GetAssembly ('System.Security.Cryptography.RijndaelManaged')
GAC Version Location
True v4.0.30319 C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ mscorlib.dll
How can I solve?
Hi, very impressed with your code package and i was looking for AES in ECB mode, because the end system i connect is using 128 - ECB AES algorithm to decrypt, so i should encrypt with same. I have end up with below code and i would like to have "text to encrypt" and "key" as parameter, no IV or no MAC required.
I am expecting something like this
Set utf8 = CreateObject("System.Text.UTF8Encoding")
aesKeyBytes = B64Decode(aesKey)
Set aesEnc = AES.CreateEncryptor_2((aesKeyBytes)) ' without IV - but not sure about the syntax
plainBytes = utf8.GetBytes_4(plaintext)
cipherBytes = aesEnc .TransformFinalBlock((plainBytes), 0, UBound(plainBytes))
Encrypt = B64Encode(cipherBytes)
Complete code:
Function Min(a, b)
Min = a
If b < a Then Min = b
End Function
Function B64Encode(bytes)
Dim result As String
Dim b64Block() As Byte
Dim b64Enc As Object
Dim utf8 As Object
Dim Offset, Length, BlockSize As Integer
Set b64Enc = CreateObject("System.Security.Cryptography.ToBase64Transform")
Set utf8 = CreateObject("System.Text.UTF8Encoding")
BlockSize = b64Enc.InputBlockSize
For Offset = 0 To LenB(bytes) - 1 Step BlockSize
Length = Min(BlockSize, UBound(bytes) - Offset)
b64Block = b64Enc.TransformFinalBlock((bytes), Offset, Length)
result = result & utf8.GetString((b64Block))
Next
B64Encode = result
End Function
Function B64Decode(b64Str)
Dim utf8 As Object
Dim bytes() As Byte
Dim b64Dec As Object
Set utf8 = CreateObject("System.Text.UTF8Encoding")
Set b64Dec = CreateObject("System.Security.Cryptography.FromBase64Transform")
bytes = utf8.GetBytes_4(b64Str)
B64Decode = b64Dec.TransformFinalBlock((bytes), 0, UBound(bytes))
End Function
Function Encrypt(plaintext, aesKey)
Dim aesKeyBytes, cipherBytes, plainBytes() As Byte
Dim aesEnc As Object
Dim utf8 As Object
Dim AES As Object
Dim aesIV() As Byte
Set AES = CreateObject("System.Security.Cryptography.RijndaelManaged")
Set utf8 = CreateObject("System.Text.UTF8Encoding")
'Set aesIV = AES.GenerateIV
aesKeyBytes = B64Decode(aesKey)
'Set aesEnc = AES.CreateEncryptor_2((aesKeyBytes), aesIV)
plainBytes = utf8.GetBytes_4(plaintext)
cipherBytes = AES.CreateEncryptor.TransformFinalBlock((plainBytes), 0, UBound(plainBytes))
Encrypt = B64Encode(cipherBytes)
End Function
Hello.
How use aes.vbs to create Excel formulas?
General I have HEX 128 bits AES CBC data like this:
063195FB35FD19DAC4C6DCD4ED773A36
the key is (also in HEX, general is deferential but in my example use zeros only) :
00000000000000000000000000000000
result is
2E026256917E06C38D6FAB8F92A0A028
Understood that in Excel press ALT+F11 (dev window), insert new module, paste code but what next? Sorry, I'm not a developer, something know but rather I'm end user that need decode thousands values like about data. Can someone help please.
BR, Krzysiek
Hello,
thanks for the script, How can I generate AES Key and Mac Keys? I don't want to use the demo keys
Hello,
thanks for the great script but I tried it in WinPE and it's not working, it failed at the first line and gave error, please advise
Set utf8 = CreateObject("System.Text.UTF8Encoding")
Its not working in winpe..any suggestions??
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.