我正在接收字符串中的二進制數據。我想將它編碼到Base64中。有沒有任何類可以做這個操作(我想要一個API)。如何將二進制字符串轉換爲base64編碼數據
4
A
回答
4
2
CryptBinaryToString ...如果你的目標到Windows平臺
這裏是一個小例子:
#include <Windows.h>
#pragma comment(lib, "crypt32.lib")
int main()
{
LPCSTR pszSource = "Man is distinguished, not only by his reason, but ...";
DWORD nDestinationSize;
if (CryptBinaryToString(reinterpret_cast<const BYTE*> (pszSource), strlen(pszSource), CRYPT_STRING_BASE64, nullptr, &nDestinationSize))
{
LPTSTR pszDestination = static_cast<LPTSTR> (HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE, nDestinationSize * sizeof(TCHAR)));
if (pszDestination)
{
if (CryptBinaryToString(reinterpret_cast<const BYTE*> (pszSource), strlen(pszSource), CRYPT_STRING_BASE64, pszDestination, &nDestinationSize))
{
// Succeeded: 'pszDestination' is 'pszSource' encoded to base64.
}
HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, pszDestination);
}
}
return 0;
}
+0
儘管這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – CodeMouse92 2015-10-06 14:01:24
相關問題
- 1. 如何將「二進制字符串」轉換爲base64?
- 2. 如何使用Perl將Base64字符串轉換爲二進制
- 3. 如何爲Base64字符串轉換爲二進制
- 4. 如何將Base64編碼二進制字符串轉換爲java中的二進制文件?
- 5. 如何將二進制數據硬編碼爲字符串
- 6. 如何將uint8數組轉換爲base64編碼字符串?
- 7. 將Base64轉換爲Java中的二進制字符串
- 8. 如何將base64字符串轉換爲二進制數組使用php
- 9. 將字符串轉換爲二進制
- 10. 將字符串轉換爲二進制
- 11. 將二進制轉換爲字符串
- 12. 將字符串轉換爲二進制
- 13. 將.net字符串對象轉換爲base64編碼字符串
- 14. 將二進制字符串轉換爲二進制文字
- 15. VBA的二進制圖像轉換爲base64編碼字符串網頁
- 16. 如何將java.sql.blob轉換爲java中的base64編碼字符串
- 17. 如何將MP3文件轉換爲Base64編碼的字符串?
- 18. ASP Classic - 將base64二進制字符串轉換爲字節數組
- 19. C++字符串轉換爲二進制代碼/二進制代碼轉換爲字符串
- 20. 將二進制字符串轉換爲二進制
- 21. Python將二進制字符串轉換爲二進制int
- 22. 計算二進制表達式 - 將字符串轉換爲二進制數據
- 23. 將SQL二進制數據轉換爲C#中的字符串
- 24. 將二進制數據轉換爲字符串
- 25. 將二進制數據幀轉換爲字符串
- 26. 將字符串轉換爲const char *(使用二進制數據)
- 27. 將二進制數據轉換爲節點中的字符串
- 28. 將二進制數據轉換爲字符串[在波斯語]
- 29. 將字符串數據轉換爲二進制圖像
- 30. 如何在Ruby中將Blowfish編碼的二進制字符串轉換爲ASCII?
你熟悉哪種語言? – jforberg 2011-06-17 11:52:13