- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
谁能猜出哪一部分是错的?我编写的代码如下。
当我读取加密文件时,我根本无法读取。并且 CryptoStream 的名为长度和位置的属性具有“NotSupportedException”,当我使用 vss 看到 cryptstream 的属性时。
我浪费了很多时间来解决这个问题.....请帮助我.....
加密[位图>>加密文件]
解密[加密文件>>文件]
public static void EncryptFile(
Bitmap bmp, string destFile, byte[] key, byte[] iv)
{
System.Security.Cryptography.RijndaelManaged rijndael =
new System.Security.Cryptography.RijndaelManaged();
rijndael.Key = key;
rijndael.IV = iv;
System.IO.FileStream outFs = new System.IO.FileStream(
destFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
System.Security.Cryptography.ICryptoTransform encryptor =
rijndael.CreateEncryptor();
System.Security.Cryptography.CryptoStream cryptStrm =
new System.Security.Cryptography.CryptoStream(
outFs, encryptor,
System.Security.Cryptography.CryptoStreamMode.Write);
MemoryStream ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Jpeg);
byte[] bs = new byte[1024];
int readLen;
while ((readLen = ms.Read(bs, 0, bs.Length)) > 0)
{
cryptStrm.Write(bs, 0, readLen);
}
ms.Close();
cryptStrm.Close();
encryptor.Dispose();
outFs.Close();
}
public static void DecryptFile(
string sourceFile, string destFile, byte[] key, byte[] iv)
{
System.Security.Cryptography.RijndaelManaged rijndael =
new System.Security.Cryptography.RijndaelManaged();
rijndael.Key = key;
rijndael.IV = iv;
System.IO.FileStream inFs = new System.IO.FileStream(
sourceFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.Security.Cryptography.ICryptoTransform decryptor =
rijndael.CreateDecryptor();
System.Security.Cryptography.CryptoStream cryptStrm =
new System.Security.Cryptography.CryptoStream(
inFs, decryptor,
System.Security.Cryptography.CryptoStreamMode.Read);
System.IO.FileStream outFs = new System.IO.FileStream(
destFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
byte[] bs = new byte[1024];
int readLen;
while ((readLen = cryptStrm.Read(bs, 0, bs.Length)) > 0)
{
outFs.Write(bs, 0, readLen);
}
outFs.Close();
cryptStrm.Close();
decryptor.Dispose();
inFs.Close();
}
最佳答案
尝试设置 rijndael 的 Mode 和 Padding 成员。
当我做类似的实现时,默认的填充模式导致了问题。
// It is reasonable to set encryption mode to Cipher Block Chaining
// (CBC). Use default options for other symmetric key parameters.
rijndael.Mode = CipherMode.CBC;
rijndael.Padding = PaddingMode.None;
关于c# - 如何解密使用 RijndaelManaged 加密的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5827600/
问题 我想用 RijndaelManaged 解密加密数据但结果始终为空("" 或数据长度全为零的字节数组)。 所有参数,盐和数据都正确,CryptoHelper.CreateRijndaelMana
我在搜索 RSACypthyServiceProvider 时在 MSDN 上找到了以下代码示例。在评论的帮助下我无法理解代码的某些部分。 什么是模数和指数? 什么是IV? 为什么他们使用 Rijnd
我想在我的应用程序中实现最安全、最可靠的对称 key 加密形式。用户应该输入密码来加密/解密,仅此而已。对于 RijndaelManaged,必须输入 key 和 IV。我不确定如何解决这种情况。现在
我有一个关于加密的问题:基本上在我的网络应用程序中我使用了 Enterprise Library 5.0 他们有一个密码 block ,所以基本上在他们提供的配置工具中我注册了一个 block 并生成
我正在尝试使用 Rijndael 256 位 block 大小、256 位 key 大小、ECB 模式和用于填充的零进行加密。 我试图使用 OpenSSL::Cipher::AES.new(256,
我可以加密图像文件。但无法解密该文件。 while ((readLen = cryptStrm.Read(bs, 0, bs.Length)) > 0) 谁能猜出哪一部分是错的?我编写的代码如下。 当
我在使用 RijndaelManaged 时遇到了一个奇怪的问题。基本上我有一个新实例,我在其中设置了 CipherMode、Padding、IV 和 Key。然后,我创建了另一个实例并将以下属性的相
我有以下 C# 代码(代码是继承的,无法编译)。这用于解密和解压缩保存的文件。 using System.Security.Cryptography; using System.Text; using
我已经从 http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptostream.aspx 中获取了解密代码
我想使用 RijndaelManaged 通过任何加盐来加密字符串,因此如果我使用相同的 key 传递加密字符串,我将收到相同的密文。我调用的方法看起来像这样 public static s
有两种方法可以为 RijndaelManaged 指定 key 和 IV。对象。一种是调用CreateEncryptor : var encryptor = rij.CreateEncryptor(E
我目前正在开发一个连接到旧网络服务的 Silverlight 应用程序。 我们的旧网络服务使用了 Silverlight 不支持的加密工具。 最后,我们决定使用 AesManaged 进行加密,但是,
关于方法... RijndaelManaged.CreateDecryptor Method (Byte[], Byte[]) Here它说的是第一个参数... The secret key to b
我正在尝试使用 .NET 中的 RijndaelManaged 类来加密文本字符串。但是,我不断收到 CryptographicException(“要解密的数据长度无效”)。此消息并不是很有帮助,尤
鉴于我将 KeySize 设置为 192,当我通过执行以下操作加密一些数据时: static void Main() { var querystrings =
我得到了这段代码: public static string DoPrefixCipherEncrypt(string strIn, byte[] btKey) { i
我花了一些时间学习如何在 .NET 中使用 RijndaelManaged 库,并开发了以下函数来测试加密文本,并对 MSDN 库稍作修改: Function encryptBytesToBytes_
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我知道有人对此提出了其他问题,但到目前为止还没有提供解决方案或正是我遇到的问题。 下面的类处理字符串的加密和解密,传入的 key 和向量始终相同。 被加密和解密的字符串总是数字,大多数工作但偶尔会在解
RijndaelManaged 类属性 KeySize 、 BlockSize 、 FeedbackSize 和 Padding 的默认值是什么?默认值是否也是最好的? 最佳答案 这是 Rijndea
我是一名优秀的程序员,十分优秀!