//获取公钥 internal string GetPublicKey() { string publicKey = RSACSP.ToXmlString(false); string encryptedPK = DESManager.DesEncrypt(publicKey); return(encryptedPK); }
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); }
internal string EncryptToBase64String(string Source, string PublicKey) { RSACSP.FromXmlString(DESManager.DesDecrypt(PublicKey)); byte[] tempByte = EncryptToByte(Source, PublicKey); string result = Convert.ToBase64String(tempByte); return(result); }
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()); }
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); }
internal byte[] EncryptToByte(string Source, string PublicKey) { RSACSP.FromXmlString(DESManager.DesDecrypt(PublicKey)); return(RSACSP.Encrypt(Encoding.UTF8.GetBytes(Source), false)); }
//获取私钥 internal string GetPrivateKey() { string privateKey = RSACSP.ToXmlString(true); return(DESManager.DesEncrypt(privateKey)); }