How to use CryptAES in AHK_H V2?

Ask for help, how to use AHK_H, etc.
bapl
Posts: 119
Joined: 17 Apr 2021, 00:24

How to use CryptAES in AHK_H V2?

20 Aug 2022, 16:13

How to use CryptAES in AHK_H V2?
I searched everywhere and did not find a solution.
bapl
Posts: 119
Joined: 17 Apr 2021, 00:24

Re: How to use CryptAES in AHK_H V2?

21 Aug 2022, 07:40

any help?

Code: Select all

Text := "Text"
Bytes := StrLen(Text)
Encoded := ""
Decoded := ""
Base64.Encode(Text, Bytes)
Msgbox(Base64)
	Msgbox Decoded := Base64.Decode(Encoded, Bytes)
ExitApp


Class Base64 {
	Static Encode(Buf, Codec := 0x40000001) {
		if Buf is String
			p := StrPtr(Buf), s := StrLen(Buf) * 2
		else p := Buf, s := Buf.Size
		if (DllCall("crypt32\CryptBinaryToString", "Ptr", p, "UInt", s, "UInt", Codec, "Ptr", 0, "Uint*", &nSize := 0) &&
			(VarSetStrCapacity(&VarOut, nSize << 1), DllCall("crypt32\CryptBinaryToString", "Ptr", p, "UInt", s, "UInt", Codec, "Str", VarOut, "Uint*", &nSize)))
			return (VarSetStrCapacity(&VarOut, -1), VarOut)
	}

	Static Decode(VarIn, Codec := 0x00000001) {
		if (DllCall("crypt32\CryptStringToBinary", "Str", VarIn, "UInt", 0, "UInt", Codec, "Ptr", 0, "Uint*", &SizeOut := 0, "Ptr", 0, "Ptr", 0) &&
			DllCall("Crypt32.dll\CryptStringToBinary", "Str", VarIn, "UInt", 0, "UInt", Codec, "Ptr", VarOut := Buffer(SizeOut), "Uint*", &SizeOut, "Ptr", 0, "Ptr", 0))
			return VarOut
	}
}
In Encoded I get this: 54 00 65 00 78 00 74 00.
In Decoded, I get an empty value.

When writing a long string to the "Text" variable, I get an empty value.
I'm probably doing something wrong.
User avatar
thqby
Posts: 433
Joined: 16 Apr 2021, 11:18
Contact:

Re: How to use CryptAES in AHK_H V2?

21 Aug 2022, 11:52

Isn't this Base64? the rettype of base64.decode is buffer.
CryptAES is the same.
https://github.com/thqby/vscode-autohotkey2-lsp/blob/main/syntaxes/ahk2_h.d.ahk#L21
bapl
Posts: 119
Joined: 17 Apr 2021, 00:24

Re: How to use CryptAES in AHK_H V2?

21 Aug 2022, 14:19

I found this already: viewtopic.php?t=81968
Thank you!

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 3 guests