0

I'm learning how to knock together classic VBScript (*.vbs files) using ActiveX (COM+?) components.

I've had some good results so far with Excel and Word - but I wanted to extend my knowledge of parameter types - such as byte arrays and such.

So I'm having a go of a simple decryptor using DES Crypto Service Provider.

I've got the object created, and can read and write settings to it - but I'm now stuck at creating an instance of "CreateDecryptor".

I thought it returned a new object, and is passed two arrays for the key and initialisation vector. But I can't get past that line. "Wrong number of arguments or invalid property assignment: 'des.CreateSecryptor'"

I wonder if I need to create a StreamWriter of some kind too, or if I just send a known length array each time to the function to decrypt?

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
SarahC
  • 113
  • 12
  • The issue here is `des.CreateDecryptor(IV, KEY)` neither `IV` or `KEY` are valid because `Array(65, 66, 67, 68, 69, 70, 71, 72)` doesn't do what you are expecting. It is just a safe array *(`VT_ARRAY`)* of integer values it is not the equivalent of a byte array `byte[]` in .Net. – user692942 Mar 14 '17 at 12:31
  • Also related [How to pass SAFEARRAY to COM object through IDispatch?](http://stackoverflow.com/q/11977806/692942) – user692942 Mar 14 '17 at 12:36

0 Answers0