본문 바로가기

Programing/.NET

(8)
[C#] Azure BlobStorage 파일 업로드 NuGet 패키지 관리자에서 Widows.Azure.Storage 참조 추가 Azure Portal Blob Storage 에서 Storage account 및 accesskey 확인 private void blobStorageUpload(Stream stream, string fileName) { String accountname = "스토리지 계정"; String accesskey = "엑세스 키"; StorageCredentials creden = new StorageCredentials(accountname, accesskey); CloudStorageAccount acc = new CloudStorageAccount(creden, useHttps: true); CloudBlobClient cli..
[C#] BarcodeLib 바코드 생성 NuGet 패키지 관리자에서 BarCodeLib 참조 추가 https://github.com/barnhill/barcodelib GitHub - barnhill/barcodelib: C# Barcode Image Generation Library C# Barcode Image Generation Library. Contribute to barnhill/barcodelib development by creating an account on GitHub. github.com 바코드 생성후 이미지 파일로 저장 public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image ..
[C#]SFTP 파일 업로드 SFTP(Secure File transfer protocol) - SSH와 마찬가지로 전송시 암호화시켜서 전송을 하게 되는데 그 중에 FTP와 같이 파일을 전송할 때 암호화 시켜서 전송합니다. SSH에 부가적으로 있는 기능들 중 하나의 기능입니다. FTP와 같은 역할을 하지만, 사용하는 포트는 FTP 포트(기본 21포트) 가 아닌 SSH 접속시 사용하는 포트를 사용하고, SSH 접속 계정으로 로그인 할 수 있는 FTP 입니다. SFTP 장점 SFTP는 하나의 연결만 필요하며 데이터 연결이 필요하지 않다. 연결이 안전하게 보호된다. 프로토콜에서 제공하는 추가 기능에는 파일 잠금, 속성 조적, 권한 작업 및 더 많은 기능이 포함된다. SFTP 단점 SSH 키의 유효성 검사 및 관리는 더복잡하다 여러 공급업..
[C#] AES256(AES/CBC/PKCS5Padding) 암/복호화 .NET 에서 AES256(AES/CBC/PKCS5Padding) 방식으로 암호화 복호화하는 방식이다. 1. HexString 방식의 Key / IV생성 using System; using System.Web; using System.IO; using System.Security.Cryptography; using System.Text; using Newtonsoft.Json.Serialization; using System.Collections.Generic; using System.Reflection; namespace Study.Model { public sealed class Crypto { ... //Key / Iv 생성 public static void GenerateKeyAndIV() { /..
[C#] RestSharp 으로 HTTP/HTTPS 통신 RestSharp 은 .NET 에서 가장 많이 사용되고있는 REST API 클라이언트 라이브러리로 프로젝트에서 사용하기위해선 먼저 NuGet 패키지를 추가해준다. 사용방법 1. public ActionResult CallAPI() { responseDto res = new responseDto(); //호출결과를 받을 DTO string URL = "URL호출주소"; //URL호출주소 Dictionary param = new Dictionary(); param.Add("변수명1", "값1"); param.Add("변수명2", "값2"); res = JsonConvert.DeserializeObject(RestSharp_Post(URL,param)); } public dynamic RestSharp_Pos..
[C#] Log파일 생성 지정경로에 폴더 및 파일이 없을 경우 파일을 생성하며 .txt 파일로 로그를 생성하는 코드입니다. public void LogWrite(string fileName, string msg) { string FilePath = "D:\\Logs\\" + fileName + "_" + DateTime.Today.ToString("yyyyMMdd") + ".txt"; string DirPath = "D:\\Logs\\"; string str = string.Empty; DirectoryInfo di = new DirectoryInfo(DirPath); FileInfo fi = new FileInfo(FilePath); try { if (di.Exists != true) Directory.CreateDirecto..
[C#]EUC-KR UTF8변환 API 통신을할때 언어셋이 다른경우 한글이 깨져서 나오는경우가 발생한다. 그때 EUC-KR 에서 UTF8로 변환하는 코드이다. URL인코딩을 한경우 HttpUtility.UrlDecode() 메소드를 통해디코딩할때 Encoding.GetEncoding(51949) 메소드를 이용하여 EUC-KR 문자로 디코딩후 해당문자를 byte에담아 문자를 출력한다. int euckrCodepage = 51949; //EUC-KR 의 코드번호 // URL Encoding된 문자열을 Decoding name = HttpUtility.UrlDecode(HttpUtility.UrlDecode(name, Encoding.GetEncoding(euckrCodepage))); System.Text.Encoding euckr = S..
[C#] HTTP/HTTPS 송수신 (HttpWebRequest/HttpWebResponse) WebClient / HttpWebRequest 웹 클라이언트 프로그래밍에서 간단한 WebClient 보다 세밀한 제어를 원할 경우, HttpWebRequest와 HttpWebResponse 클래스를 사용할 수 있다. 사실 WebClient는 HttpWebRequest와 HttpWebResponse 클래스를 내부적으로 사용하고 있는 Wrapper 클래스이다. 방법1. WebClient public JsonResultEntity HttpTest1(string str, int Num) { JsonResultEntity entity = new JsonResultEntity(); try { string URL = "API 호출주소"; WebClient webClient = new WebClient(); Syst..