Hi All,
How I can check encoded string is correct, which is converted blob data using Base64.
We are uploading encoded (using base64 Encoding) Blob data to "Docuware", some time it is not accessible from "Docuware", so before uploading, want to double check.
I had read few articles to solve above issue, compare with regexp ("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$") but no hope.
And at last I converted to blob (base64 Decoding) again and comparing with length of the blob, but after conversion length is miss matching, can you advice.
Please find the attached object for reference n_cryptapi (thanks to rolland and Chris)
using
of_base64encode
ULong lul_MsgLen, lul_BufLen
string ls_temp
setnull(ls_temp)
// determine size of the encoded buffer
lul_MsgLen = Len(ablb_message)
If Not CryptBinaryToString(ablb_message, lul_MsgLen, &
CRYPT_STRING_BASE64, ls_temp, lul_BufLen) Then
LastErrCode = of_GetLastError(LastErrText)
LastFunction = "CryptBinaryToString"
//messagebox( 'LastErrCode 1', LastErrCode )
Return False
End If
// allocate encoded buffer
as_encoded = Space(lul_BufLen)
// encode the binary data as Base64 string
If Not CryptBinaryToString(ablb_message, lul_MsgLen, &
CRYPT_STRING_BASE64 + CRYPT_STRING_NOCRLF, &
as_encoded, lul_BufLen) Then
LastErrCode = of_GetLastError(LastErrText)
LastFunction = "CryptBinaryToString"
//messagebox( 'LastErrCode 2', LastErrCode )
Return False
End If
//
Return True
and
of_base64decode
// Declarations.
ULong lul_len
ULong lul_buflen
ULong lul_skip
ULong lul_pflags
Boolean lb_rc
lul_len = Len ( as_encoded )
lul_buflen = lul_len
ablb_value = Blob (Space (lul_len))
lb_rc = CryptStringToBinary ( as_encoded , lul_len, &
CRYPT_STRING_BASE64, ablb_value , &
lul_buflen, lul_skip, lul_pflags )
Return lb_rc
Regards
Antony
Thank you very much.
I will download PB version 2021, and test the code and will come back
Regards
Antony