コード例 #1
0
 public string BASE64_Convert(bool action, string strData)
 {
     if (action)
     {
         return(BASE64_Main.DecodeS(strData, "UTF-8"));
     }
     else
     {
         return(BASE64_Main.EncryptS(strData, "UTF-8"));
     }
 }
コード例 #2
0
ファイル: RSA_Gen.cs プロジェクト: PixelFrame/CryptoSharp
        /// <summary>
        /// 按PKCS#1格式生成RSA公钥并进行BASE64转换
        /// </summary>
        /// <param name="n"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string PKCS1_Pub_Gen_S(BigInteger n, BigInteger e)
        {
            string strPKCS = new string(Encoding.UTF8.GetChars(BASE64_Main.EncryptB(PKCS1_Pub_Gen(n, e))));
            int    count   = 64;

            while (count < strPKCS.Length)
            {
                strPKCS = strPKCS.Insert(count, "\n");
                count  += 65;
            }
            strPKCS = "-----BEGIN RSA PUBLIC KEY-----\n" + strPKCS + "\n-----END RSA PUBLIC KEY-----\n";
            return(strPKCS);
        }
コード例 #3
0
ファイル: RSA_Gen.cs プロジェクト: PixelFrame/CryptoSharp
        /// <summary>
        /// 按PKCS#1格式生成RSA私钥并进行BASE64转换
        /// </summary>
        /// <returns></returns>
        public static string PKCS1_Pri_Gen_S()
        {
            string strPKCS = new string(Encoding.UTF8.GetChars(BASE64_Main.EncryptB(PKCS1_Pri_Gen())));
            int    count   = 64;

            while (count < strPKCS.Length)
            {
                strPKCS = strPKCS.Insert(count, "\n");
                count  += 65;
            }
            strPKCS = "-----BEGIN RSA PRIVATE KEY-----\n" + strPKCS + "\n-----END RSA PRIVATE KEY-----\n";
            return(strPKCS);
        }
コード例 #4
0
ファイル: RSA_Read.cs プロジェクト: PixelFrame/CryptoSharp
 /// <summary>
 /// 读取经过BASE64编码的PKCS#1格式RSA公钥
 /// </summary>
 /// <param name="baPKCS1"></param>
 /// <returns></returns>
 public static BigInteger[] PKCS1_Pub_Read(string strPKCS1)
 {
     try
     {
         strPKCS1 = strPKCS1.Remove(0, 31);
         strPKCS1 = strPKCS1.Remove(strPKCS1.LastIndexOf("\n-----END RSA PUBLIC KEY-----\n"));
         strPKCS1 = strPKCS1.Replace("\n", "");
     }
     catch (Exception inner)
     {
         throw new RSAKeyFormatErrorException(inner);
     }
     return(PKCS1_Read(BASE64_Main.DecodeB(Encoding.UTF8.GetBytes(strPKCS1))));
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: PixelFrame/CryptoSharp
        static void BASE64_TEST()
        {
            string str    = "简体中文\n繁體中文\nカタカナ\nひらがな\nEnglish\n12345";
            string strEnc = BASE64_Main.EncryptS(str, "GBK");

            Console.Out.WriteLine("GBK: " + strEnc);
            Console.Out.WriteLine(BASE64_Main.DecodeS(strEnc, "GBK"));
            strEnc = BASE64_Main.EncryptS(str, 65001);
            Console.Out.WriteLine("UTF-8: " + strEnc);
            Console.Out.WriteLine(BASE64_Main.DecodeS(strEnc, 65001));
            strEnc = BASE64_Main.EncryptS(str, "UTF-16");
            Console.Out.WriteLine("UTF-16LE: " + strEnc);
            Console.Out.WriteLine(BASE64_Main.DecodeS(strEnc, "UTF-16"));
        }
コード例 #6
0
 public byte[] BASE64_Decrypt(string strData)
 {
     return(BASE64_Main.DecodeB(Encoding.UTF8.GetBytes(strData)));
 }
コード例 #7
0
 public string BASE64_Encrypt(byte[] baData)
 {
     return(BASE64_Main.EncryptS(baData, "UTF-8"));
 }