1

When trying to make a secure encryption system for some secret keys, I wanted to see if we can encrypt the file containing the key in VBScript using AES

Looking at other posts, I found that:

'-----------------------------------------------------
Dim obj,arr,i,r,str,enc,asc
dim bytes,bytesd,s,sc,sd
set obj=WScript.CreateObject("System.Security.Cryptography.RijndaelManaged")
Set asc = CreateObject("System.Text.UTF8Encoding")
s="This is a private message"
bytes=asc.GetBytes_4(s)
obj.GenerateKey()
obj.GenerateIV()
set enc=obj.CreateEncryptor()
set dec=obj.CreateDecryptor()

bytec=enc.TransformFinalBlock((bytes),0,lenb(bytes))
sc=asc.GetString((bytec))
msgbox sc

byted=dec.TransformFinalBlock((bytec),0,lenb(bytec))
sd=asc.GetString((byted))
msgbox sd
'-----------------------------------------------------

This is useful to encrypt a string, but, it will be possible to set a default key and IV to the AES encryption, because I want to encrypt a and decrypt file, so I need to have already a key and IV to decrypt.

Is there any way to encrypt a file in VBScript using AES?

Anic17
  • 712
  • 5
  • 18
  • Before writing this post I already looked at the post you have answered. The problem is that when I try to use a custom key, like `obj.Key = "cmsOYp1fH8SmIzVf37WVuYUg7B1ijDhA"` it throws an error. – Anic17 Jun 02 '20 at 14:49
  • This is now my question, my question is how to generate a custom IV and a custom key, not random, so I could decrypt it if I have the two values. Also, I have said to encrypt a file, not a string. Thanks. – Anic17 Jun 04 '20 at 16:48

0 Answers0