/// <summary> /// 使用RSA进行非对称加密,使用默认公钥 /// </summary> /// <param name="inputBuffer">待加密的字节数组</param> /// <returns>加密后的字节数组</returns> public byte[] Encrypt(byte[] inputBuffer) { if (inputBuffer.Length <= EncryptCount) { return(RSACSP.Encrypt(inputBuffer, false)); } else { List <byte> list = new List <byte>(); MemoryStream ms = new MemoryStream(inputBuffer); byte[] buffer = new byte[EncryptCount]; while (ms.Read(buffer, 0, EncryptCount) > 0) { list.AddRange(RSACSP.Encrypt(buffer, false)); } return(list.ToArray()); } }
/// <summary> /// 使用RSA进行非对称加密 /// </summary> /// <param name="inputBuffer">待加密的字节数组</param> /// <param name="keyBlob">RSA公钥Blob字节数组</param> /// <returns>加密后的字节数组</returns> public byte[] Encrypt(byte[] inputBuffer, byte[] keyBlob) { using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) { RSA.ImportCspBlob(keyBlob); if (inputBuffer.Length <= EncryptCount) { return(RSA.Encrypt(inputBuffer, false)); } else { List <byte> list = new List <byte>(); MemoryStream ms = new MemoryStream(inputBuffer); byte[] buffer = new byte[EncryptCount]; while (ms.Read(buffer, 0, EncryptCount) > 0) { list.AddRange(RSACSP.Encrypt(buffer, false)); } return(list.ToArray()); } } }