Created
July 25, 2020 01:47
-
-
Save jayu108/4ca24098ad634bd6fc171448aa549b5a to your computer and use it in GitHub Desktop.
C# -- string 을 base64 string 으로 만들기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
namespace Test | |
{ | |
public class Base64Converter | |
{ | |
public static string GetUTF8Base64String(string username, string password) | |
{ | |
string txt = username + ":" + password; | |
byte[] bytesUTF8 = Encoding.UTF8.GetBytes(txt); // txt 문자열의 UTF8 인코딩에 해당하는 byte 배열 구함. | |
//byte[] bytesUnicode = Encoding.Unicode.GetBytes(txt); | |
//foreach(var x in bytesUTF8) | |
//{ | |
// Console.Write($"{x} "); | |
//} | |
//Console.WriteLine(); | |
//foreach (var x in bytesUnicode) | |
//{ | |
// Console.Write($"{x} "); | |
//} | |
//Console.WriteLine(); | |
string base64UTF8 = Convert.ToBase64String(bytesUTF8); | |
//string base64Unicode = Convert.ToBase64String(bytesUnicode); | |
//Console.WriteLine($" base64UTF8 ==> {base64UTF8}"); | |
//Console.WriteLine($" base64Unicode ==> {base64Unicode}"); | |
return base64UTF8; | |
} | |
public static string GetUnicodeBase64String(string username, string password) | |
{ | |
string txt = username + ":" + password; | |
byte[] bytesUnicode = Encoding.Unicode.GetBytes(txt); // txt 문자열의 Unicode 인코딩에 해당하는 byte 배열 구함. | |
//foreach (var x in bytesUnicode) | |
//{ | |
// Console.Write($"{x} "); | |
//} | |
//Console.WriteLine(); | |
string base64Unicode = Convert.ToBase64String(bytesUnicode); | |
//Console.WriteLine($" base64Unicode ==> {base64Unicode}"); | |
return base64Unicode; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment