如何使用 AES 在 VBScript 中加密? [英] How to encrypt in VBScript using AES?

查看:15
本文介绍了如何使用 AES 在 VBScript 中加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 Rijndael/AES 加密一些数据://en.wikipedia.org/wiki/VBScript" rel="noreferrer">VBScript 使用特定键和 IV 值.有什么好的函数库或COM组件可以很好用吗?

I am looking to encrypt some data using Rijndael/AES in VBScript using a specific key and IV value. Are there any good function libraries or COM components that would be good to use?

我查看了CAPICOM;它只允许密码短语,不允许设置特定的密钥和 IV 值.

I looked at CAPICOM; it allows a passphrase only, and won't allow setting specific key and IV values.

推荐答案

一种方法是在 vbscript 中声明加密类,不需要外部添加 COM 对象或包装器.以下示例采用字符串,使用 Rijndael 托管类进行加密和解密:

One way is to declare encryption classes within vbscript, without needing external added COM objects or wrapper. The following example takes a string, encrypts and decrypts using Rijndael managed class:

'-----------------------------------------------------
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
'-----------------------------------------------------

这篇关于如何使用 AES 在 VBScript 中加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆