View Single Post
Old 18th October 2019, 06:20   #10
otrub
Junior Member
 
Join Date: Mar 2018
Posts: 8
Hi, Anders. Thanks very much for your reply. I tried to solve with your plugin and code. But results are different( I should get the same, because application on the server side use same algo. What do dou think about compatibility with your solution?

I implemented solution like that. I use vbs script to get correct result. But I think it's bad way, because I'm passing secret key and vector via args(((

Quote:
On Error Resume Next
Dim resp,obj,arr,i,r,str,enc,asc,objStream,bin,bytes,bytesd,s,sc,sd,crypt,file,content,fso,result
Const typeBinary = 1
Const forReading = 1, forWriting = 2, forAppending = 8
Set objArgs = Wscript.Arguments

Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(objArgs(1), 1, False, -1)
content = file.ReadAll
file.Close

If objArgs(0) = 1 Then
result = decryptAES128(content, objArgs(2), objArgs(3))
ElseIf objArgs(0) = 2 Then
result = encryptAES128(content, objArgs(2), objArgs(3))
End If

Set file = fso.OpenTextFile(objArgs(1), 2, False, -1)
file.WriteLine(result)
file.Close

If E******mber = 0 Then
Wscript.Quit(0)
Else
'MsgBox Err.Description
Wscript.Echo(Err.Description)
Wscript.Quit(1)
End If

private function decryptAES128(base64encrypted, key, iv)
Set obj=WScript.CreateObject("System.Security.Cryptography.RijndaelManaged")
Set asc = CreateObject("System.Text.UTF8Encoding")
Set crypt = WScript.CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")

obj.KeySize = 128
obj.Key = crypt.ComputeHash_2(asc.GetBytes_4(key))
obj.IV = crypt.ComputeHash_2(asc.GetBytes_4(iv))

Set dec = obj.CreateDecryptor()

bin = decodeBase64(base64encrypted)
byted = dec.TransformFinalBlock((bin),0,lenb(bin))
sd = asc.GetString((byted))

decryptAES128 = sd
end function

private function encryptAES128(source, key, iv)
Set obj=WScript.CreateObject("System.Security.Cryptography.RijndaelManaged")
Set asc = CreateObject("System.Text.UTF8Encoding")
Set crypt = WScript.CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")

obj.KeySize = 128
obj.Key = crypt.ComputeHash_2(asc.GetBytes_4(key))
obj.IV = crypt.ComputeHash_2(asc.GetBytes_4(iv))

Set enc = obj.CreateEncryptor()

bin = asc.GetBytes_4(source)
byted = enc.TransformFinalBlock((bin),0,lenb(bin))

encryptAES128 = encodeBase64(byted)
end function

private function encodeBase64(bytes)
dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
' Create temporary node with Base64 data type
Set EL = DM.createElement("tmp")
EL.DataType = "bin.base64"
' Set bytes, get encoded String
EL.NodeTypedValue = bytes
encodeBase64 = EL.Text
end function

private function decodeBase64(base64)
dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
' Create temporary node with Base64 data type
Set EL = DM.createElement("tmp")
EL.DataType = "bin.base64"
' Set encoded String, get bytes
EL.Text = base64
decodeBase64 = EL.NodeTypedValue
end function
If you have some advices to me, please tell me how I can use NSIS plugin and save compability.
Thanks a lot for your care.
otrub is offline   Reply With Quote