encode = encodeBase64("My name is Inigo Montoya")
decode = decodeBase64(encode)
'DECLARE LIBRARY ".\pipecom"
' FUNCTION pipecom$ (cmd AS STRING)
'END DECLARE
'FUNCTION encodeBase64$ (encode AS STRING)
' DIM encoded AS STRING
' DIM encodefile AS INTEGER
' encodefile = FREEFILE
' OPEN "3nc0deb64" FOR OUTPUT AS #encodefile
' PRINT #encodefile, encode
' CLOSE #encodefile
' encoded = pipecom("certutil -encode 3nc0deb64 3nc0dedb64 && type 3nc0dedb64 && del 3nc0dedb64 && del 3nc0deb64")
' encoded = MID$(encoded, INSTR(encoded, "-----BEGIN CERTIFICATE-----") + LEN("-----BEGIN CERTIFICATE-----") + 1)
' encoded = MID$(encoded, 1, INSTR(encoded, "-----END CERTIFICATE-----") - 2)
' encodeBase64 = encoded
'END FUNCTION
'FUNCTION decodeBase64$ (decode AS STRING)
' DIM decoded AS STRING
' DIM decodefile AS INTEGER
' decodefile = FREEFILE
' OPEN "d3c0deb64" FOR OUTPUT AS #decodefile
' PRINT #decodefile, decode
' CLOSE #decodefile
' decoded = pipecom("certutil -decode d3c0deb64 d3c0dedb64 && type d3c0dedb64 && del d3c0deb64 && del d3c0dedb64")
' decoded = MID$(decoded, _INSTRREV(decoded, "successfully.") + 1 + LEN("successfully."))
' decoded = MID$(decoded, 1, LEN(decoded) - 1)
' decodeBase64 = decoded
'END FUNCTION
CONST CRYPT_STRING_NOCRLF
= &H40000000 CONST CRYPT_STRING_BASE64
= &H00000001
encode
= encode
+ CHR$(0) lengthencode
= LEN(encode
)
a
= CryptBinaryToString
(_OFFSET(encode
), lengthencode
, CRYPT_STRING_BASE64
OR CRYPT_STRING_NOCRLF
, 0, _OFFSET(lengthencoded
)) 'Calculate buffer length
encoded
= SPACE$(lengthencoded
) encodeBase64 = ""
a
= CryptBinaryToString
(_OFFSET(encode
), lengthencode
, CRYPT_STRING_BASE64
OR CRYPT_STRING_NOCRLF
, _OFFSET(encoded
), _OFFSET(lengthencoded
)) 'Acual conversion
encodeBase64 = encoded
encodeBase64 = ""
CONST CRYPT_STRING_BASE64_ANY
= &H00000006
decode
= decode
+ CHR$(0) lengthdecode
= LEN(decode
) - 1 a
= CryptStringToBinary
(_OFFSET(decode
), lengthdecode
, CRYPT_STRING_BASE64_ANY
, 0, _OFFSET(lengthdecoded
), 0, 0) 'Calculate buffer length
decoded
= SPACE$(lengthdecoded
) decodeBase64 = ""
a
= CryptStringToBinary
(_OFFSET(decode
), lengthdecode
, CRYPT_STRING_BASE64_ANY
, _OFFSET(decoded
), _OFFSET(lengthdecoded
), 0, 0) 'Actual conversion
decodeBase64 = decoded
decodeBase64 = ""
PRINT #encodefile
, encode
encoded = pipecom("base64 3nc0deb64")
encodeBase64
= MID$(encoded
, 1, LEN(encoded
) - 1)
PRINT #decodefile
, decode
decoded = pipecom("base64 -d d3c0deb64")
decodeBase64 = decoded