Code: Select all
B64 := Base64Enc_FromFile(A_AhkPath)
Code: Select all
File = C:\Users\Documents\decoded_base64_encoded.txt
Base64Dec_ToFile(B64, File)
How do I store this content shown on the image into a variable, without needing to previous save it into a text file?
I mean something like:
Code: Select all
content = Base64Dec(B64)
I have tested many base64decode functions found here on the forum, but none gives the same output as the one saved on the txt file/shown on the image.
It might be missing to add something.
Code: Select all
Base64Dec_ToFile(ByRef B64, FileName) {
nBytes := Base64Dec(B64, Bin)
FileOpen(FileName, "w").RawWrite(Bin, nBytes)
}
@SKAN any idea? I have tested all your b64 functions
Current script:
Code: Select all
b64 := Base64Enc_FromFile(A_AhkPath)
File = C:\Users\Documents\decodedb64.txt
Base64Dec_ToFile(B64, File)
ExitApp
Base64Enc( ByRef Bin, nBytes, LineLength := 64, LeadingSpaces := 0 ) { ; By SKAN / 18-Aug-2017
Local Rqd := 0, B64, B := "", N := 0 - LineLength + 1 ; CRYPT_STRING_BASE64 := 0x1
DllCall( "Crypt32.dll\CryptBinaryToString", "Ptr",&Bin ,"UInt",nBytes, "UInt",0x1, "Ptr",0, "UIntP",Rqd )
VarSetCapacity( B64, Rqd * ( A_Isunicode ? 2 : 1 ), 0 )
DllCall( "Crypt32.dll\CryptBinaryToString", "Ptr",&Bin, "UInt",nBytes, "UInt",0x1, "Str",B64, "UIntP",Rqd )
If ( LineLength = 64 and ! LeadingSpaces )
Return B64
B64 := StrReplace( B64, "`r`n" )
Loop % Ceil( StrLen(B64) / LineLength )
B .= Format("{1:" LeadingSpaces "s}","" ) . SubStr( B64, N += LineLength, LineLength ) . "`n"
Return RTrim( B,"`n" )
}
Base64Dec( ByRef B64, ByRef Bin ) { ; By SKAN / 18-Aug-2017
Local Rqd := 0, BLen := StrLen(B64) ; CRYPT_STRING_BASE64 := 0x1
DllCall( "Crypt32.dll\CryptStringToBinary", "Str",B64, "UInt",BLen, "UInt",0x1
, "UInt",0, "UIntP",Rqd, "Int",0, "Int",0 )
VarSetCapacity( Bin, 128 ), VarSetCapacity( Bin, 0 ), VarSetCapacity( Bin, Rqd, 0 )
DllCall( "Crypt32.dll\CryptStringToBinary", "Str",B64, "UInt",BLen, "UInt",0x1
, "Ptr",&Bin, "UIntP",Rqd, "Int",0, "Int",0 )
Return Rqd
}
Base64Enc_FromFile(FileName) {
FileGetSize, nBytes, %FileName%
FileRead, Bin, *c %FileName%
return Base64Enc(Bin, nBytes)
}
Base64Dec_ToFile(ByRef B64, FileName) {
nBytes := Base64Dec(B64, Bin)
FileOpen(FileName, "w").RawWrite(Bin, nBytes)
}