eclipse 가 아닌 다른방식으로 컴파일을 했을때 아래와 같은 warring message 를 볼수있습니다.


sun.misc.BASE64Incoder is Sun proprietary API and may be removed in a future release

sun.misc.BASE64Decoder is Sun proprietary API and may be removed in a future release


http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html


이 이야기는 간단히 이야기해서 sun.* 패키지의 클래스들은 사용하지 말고 다른것으로 바꾸라는 경고입니다.


대체할만 한것으로는


http://www.source-code.biz/base64coder/java/


http://huikyun.tistory.com/234


http://devday.tistory.com/2027


고맙습니다.

Posted by 빨강토끼
,

DES 암호화나 Base64 에 대한 설명은 하지않겠습니다.(구글이나 네이버 검색하세요. ^^ )

CBC 와 PKCS7 에 대한 설명은 http://blog.cjred.net/141 를 참고하세요.


  1. using System.Security.Cryptography  
  2.   
  3.   
  4. namespace crypto{  
  5.     class DES{  
  6.         byte[] desKey;  
  7.         byte[] desVector;  
  8.   
  9.         public DES(string key, string vector)  
  10.         {  
  11.             // key와 vector 값을 byte[] 형으로 변환시킵니다.  
  12.             this.desKey = System.Text.Encoding.Default.GetBytes(key);  
  13.             this.desVector = System.Text.Encoding.Default.GetBytes(vector);  
  14.   
  15.             if (this.desVector.Length != 8)  
  16.             {  
  17.                 // DES 암호화키는 8자리입니다.  
  18.                 throw (new Exception("Invalid key. Key length must be 8 byte."));  
  19.             }  
  20.   
  21.             // DES 암호화 관련 클래스를 생성합니다.  
  22.             DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();  
  23.             // cipher 모드를 CBC 방식으로 사용합니다.  
  24.             cryptoProvider.Mode = CipherMode.CBC;  
  25.             // Padding Mode 를 PKCS7 으로 사용합니다.(PKCS5 와 동일합니다.)  
  26.             cryptoProvider.Padding = PaddingMode.PKCS7;  
  27.         }  
  28.   
  29.         public string Encrypt(string plainText)  
  30.         {  
  31.             if (string.IsNullOrEmpty(plainText))  
  32.             {  
  33.                 throw new ArgumentException("the string which needs to be encrypted can not be null.");  
  34.             }  
  35.               
  36.             MemoryStream memoryStream = new MemoryStream();  
  37.             CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(key, vector), CryptoStreamMode.Write);  
  38.             StreamWriter writer = new StreamWriter(cryptoStream, Encoding.Default);  
  39.              
  40.             writer.Write(plainText);  
  41.             writer.Flush();  
  42.             cryptoStream.FlushFinalBlock();  
  43.             writer.Flush();  
  44.   
  45.             UTF8Encoding utf8Enc = new UTF8Encoding();  
  46.             String cypherText = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);  
  47.             return cypherText;  
  48.         }  
  49.   
  50.         public string Decrypt(string cypherText)  
  51.         {  
  52.             string plainText;  
  53.             if (string.IsNullOrEmpty(cypherText))  
  54.             {  
  55.                 throw new ArgumentException("the string which needs to be encrypted can not be null.");  
  56.             }  
  57.              
  58.             MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(cypherText));  
  59.             CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(key, vector), CryptoStreamMode.Read);  
  60.             StreamReader reader = new StreamReader(cryptoStream);  
  61.   
  62.             plainText = reader.ReadToEnd();  
  63.             return plainText;  
  64.         }  
  65.   
  66.         static void Main(string[] args)  
  67.         {  
  68.             DES des = new DES("kyString","123456");  
  69.             string cypherText = des.Encrypt("test string");  
  70.             console.WriteLine(cypherText);  
  71.   
  72.             string plainText = des.Decrypt(cypherText);  
  73.             console.WriteLine(plainText);  
  74.         }  
  75.     }  
  76. }  


Posted by 빨강토끼
,