반응형
base64 인코딩
참고 : https://www.youtube.com/watch?v=9oeAoWPXtUg&list=PLlsKgYi2Lw722PMqESdivKJQgRtJAdbzn&index=23
https://www.base64decode.org/ ==> 온라인 base 인코딩, 디코딩 확인 사이트
C# 에서 string 문자열을 utf8 용 base64 인코딩 문자열로 바꾸는 함수 만들자..
< 소스 >
This file contains hidden or 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; | |
} | |
} | |
} |
반응형
'C#' 카테고리의 다른 글
C# -- popup listbox window 구현하기 (0) | 2020.09.16 |
---|---|
C# -- listbox 에서 선택해제하기 (deselect) (0) | 2020.08.17 |
C# -- datagridview 에서 virtual mode 사용하기 (0) | 2019.12.20 |
C# -- winform 에서 double buffer 사용하기 (deprecated) (0) | 2019.12.05 |
C# -- 관리자 권한으로 실행되는 프로그램 만들기 (0) | 2019.12.04 |