Пример #1
0
        //获取公钥
        internal string GetPublicKey()
        {
            string publicKey   = RSACSP.ToXmlString(false);
            string encryptedPK = DESManager.DesEncrypt(publicKey);

            return(encryptedPK);
        }
Пример #2
0
        internal string DecryptFromBase64String(string Source, string PrivateKey)
        {
            byte[] tempByte = System.Convert.FromBase64String(Source);
            RSACSP.FromXmlString(DESManager.DesDecrypt(PrivateKey));
            string result = Encoding.UTF8.GetString(RSACSP.Decrypt(tempByte, false));

            return(result);
        }
Пример #3
0
        internal string EncryptToBase64String(string Source, string PublicKey)
        {
            RSACSP.FromXmlString(DESManager.DesDecrypt(PublicKey));
            byte[] tempByte = EncryptToByte(Source, PublicKey);
            string result   = Convert.ToBase64String(tempByte);

            return(result);
        }
Пример #4
0
        internal string Encrypt(string Source, string PublicKey)
        {
            RSACSP.FromXmlString(DESManager.DesDecrypt(PublicKey));
            byte[]        tempByte = EncryptToByte(Source, PublicKey);
            StringBuilder sb       = new StringBuilder();

            foreach (byte b in tempByte)
            {
                sb.Append(b.ToString().PadLeft(3, '0'));
            }
            return(sb.ToString());
        }
Пример #5
0
        internal string Decrypt(string Source, string PrivateKey)
        {
            int ByteNum = Source.Length / 3;

            byte[]        tempByte = new byte[ByteNum];
            StringBuilder sb       = new StringBuilder();

            try
            {
                for (int i = 0; i < ByteNum; i++)
                {
                    tempByte[i] = Convert.ToByte(Source.Substring(i * 3, 3), 10);
                }
            }
            catch
            {
                throw new Exception("密文内容有误");
            }
            RSACSP.FromXmlString(DESManager.DesDecrypt(PrivateKey));
            string result = Encoding.UTF8.GetString(RSACSP.Decrypt(tempByte, false));

            return(result);
        }
Пример #6
0
 internal byte[] EncryptToByte(string Source, string PublicKey)
 {
     RSACSP.FromXmlString(DESManager.DesDecrypt(PublicKey));
     return(RSACSP.Encrypt(Encoding.UTF8.GetBytes(Source), false));
 }
Пример #7
0
        //获取私钥
        internal string GetPrivateKey()
        {
            string privateKey = RSACSP.ToXmlString(true);

            return(DESManager.DesEncrypt(privateKey));
        }