File tree Expand file tree Collapse file tree
packages/passkeys/passkeys_windows/windows Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,15 +94,24 @@ namespace passkeys_windows
9494 }
9595
9696 std::string base64 (base64_size, 0 );
97+ DWORD written_size = base64_size;
9798 if (!CryptBinaryToStringA (data, static_cast <DWORD>(size),
9899 CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF,
99- &base64[0 ], &base64_size ))
100+ &base64[0 ], &written_size ))
100101 {
101102 throw std::runtime_error (" Failed to encode base64" );
102103 }
103104
104- // Remove null terminator
105- base64.resize (base64_size - 1 );
105+ // Resize to actual content length (excluding null terminator if present)
106+ // CryptBinaryToStringA writes 'written_size' chars which may include null terminator
107+ if (written_size > 0 && base64[written_size - 1 ] == ' \0 ' )
108+ {
109+ base64.resize (written_size - 1 );
110+ }
111+ else
112+ {
113+ base64.resize (written_size);
114+ }
106115
107116 // Base64 to Base64url conversion
108117 for (char &c : base64)
You can’t perform that action at this time.
0 commit comments