我正在学习如何使用ActiveX(COM +?)组件将经典VBScript(* .vbs文件)拼凑在一起。
到目前为止,我已经用Excel和Word获得了一些好的结果 - 但我想扩展我对参数类型的了解 - 比如字节数组等。
所以我正在使用DES加密服务提供商来解决一个简单的解密器。
我已经创建了对象,并且可以读取和写入设置 - 但我现在仍然在创建“CreateDecryptor”的实例。
我认为它返回了一个新对象,并为密钥和初始化向量传递了两个数组。但我无法超越那条线。 “错误的参数数量或无效的属性赋值:'des.CreateSecryptor'”
我想知道是否需要创建某种类型的StreamWriter,或者我是否每次只发送一个已知长度的数组来解密?
Set utf = CreateObject("System.Text.UTF8Encoding")
Set des = CreateObject("System.Security.Cryptography.DESCryptoServiceProvider")
WScript.echo "Block size: " & des.BlockSize
IV = Array(65, 66, 67, 68, 69, 70, 71, 72)
KEY = Array(65, 66, 67, 68, 69, 70, 71, 72)
Set decryptor = des.CreateDecryptor(IV, KEY) ' Wrong number of parameters?
'The VB.Net equivalent of what I want to do...
'fileStream = new FileStream(strFilePath, FileMode.Open);
'DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
'cryptoStream = new CryptoStream(fileStream, dESCryptoServiceProvider.CreateDecryptor(this.bytFileKey, this.bytFileIV), CryptoStreamMode.Read);
'streamReader = new StreamReader(cryptoStream);
'StringBuilder stringBuilder = new StringBuilder(20480);
'while (streamReader.Peek() > -1){
' stringBuilder.Append(streamReader.ReadLine());
'}
'Convert the string to a byte array and hash it
bytes = utf.GetBytes_4("TESTING")
'Convert the byte array to a hex string
outstr = ""
For pos = 1 To Lenb(bytes)
outstr = outstr & LCase(Right("0" & Hex(Ascb(Midb(bytes, pos, 1))), 2))
Next
WScript.echo outstr
Set decryptor = Nothing
Set des = Nothing
Set utf = Nothing