Tag: 加密

“坏数据”CryptographicException

首先,我只是为了学术目的而编写了以下代码。 我说这个的原因是因为我没有将它放在生产环境中,因此我“绕过”了我需要做的一些开销,我只需要能够使用加密/解密字符串下面的代码。 我能够做到这一点,但由于某种原因,我开始收到“CryptographicException Bad Data”,并且不确定是什么原因造成了这个问题。 private string RSAEncrypt(string value) { byte[] encryptedData = Encoding.Unicode.GetBytes(value); CspParameters cspParams = new CspParameters(); cspParams.KeyContainerName = _rsaContainerName; using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048,cspParams)) { encryptedData = RSA.Encrypt(encryptedData, false); return Convert.ToBase64String(encryptedData); } } private string RSADecrypt(string value) { byte[] encryptedData = Encoding.Unicode.GetBytes(value); CspParameters cspParams = new CspParameters(); cspParams.KeyContainerName = _rsaContainerName; using […]

C#WPF加密

我想使用C#WPF加密密码。 什么是最好的算法(并且易于实现)? 我想要一些关于如何使用它的例子……

使用File.Encrypt加密文件,然后将其解密为内存流

我需要实现一个简单的文件加密,然后在需要时将其解密到内存流。 最简单的方法似乎是使用File.Encrypt执行此操作,但是是否可以将文件解密为内存流,而不是在将文件读取到内存流之前解密文件,从而将文件暴露一段时间? 如果File.Encrypt不是这种情况的最佳方式,你会推荐什么?

PHP中的MACTripleDES

我试图获得相当于C# MACTripleDES类的MAC TripleDES。 我试过跟随mcrypt() ,但这只是在TripleDES中编码。 我需要获得一个等效的MACTripleDES字符串作为在C#中生成的字符串来validation消息。 我也查看了PHP的hash_hmac()函数,但它没有给出使用TripleDES生成MAC的选项

使用AES和rsaEncryption(PKCS#1 v1.5填充而不是v2(OAEP)填充)的EnvelopedCMS可能吗?

我一直在使用.NET进行加密。 到目前为止,我将3DES(Oid 1.2.840.113549.3.7)与rsaEncryption(Oid 1.2.840.113549.1.1.1,RSAES-PKCS1-v1_5)结合使用。 虽然第一个现在已被AES取代(Oid 2.16.840.1.101.3.4.1.42),但我仍然必须使用rsaEncryption / RSAES-PKCS1-v1_5 ,而不是RSAES-OAEP 。 如果我只是将另一个参数传递给我正在调用的EnvelopedCMS构造函数,我可以从3DES切换到AES: ContentInfo plainContent = new ContentInfo(new Oid(“1.2.840.113549.1.7.1”), data); EnvelopedCms encryptedMessage = new EnvelopedCms(plainContent); // using 3DES // EnvelopedCms encryptedMessage = new EnvelopedCms(plainContent, new AlgorithmIdentifier(new Oid(“2.16.840.1.101.3.4.1.42”))); // for AES (id-aes256-CBC) CmsRecipient recipient = new CmsRecipient(cert); encryptedMessage.Encrypt(recipient); byte[] encryptedBytes = encryptedMessage.Encode(); 到目前为止这很好。 不幸的是,有些收件人无法解密我的邮件,尽管他们能够解密AES。 查看ASN.1结构告诉我,不仅3DES改为AES,而且rsaEncryption(1.2.840.113549.1.1.1)被RSAES-OAEP (1.2.840.113549.1.1.7)取代。 我可以以某种方式强迫仍然使用EnvelopedCMS的RSAES-PKCS1-v1_5吗? 或者您是否在切换3DES-> […]

使用RsaProtectedConfigurationProvider加密/解密app.config部分

在我们的程序安装过程中,我们运行此方法来加密app.config的各个部分: // Get the application configuration file. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Define the Rsa provider name. const string provider = “RsaProtectedConfigurationProvider”; // Get the section to protect. ConfigurationSection connStrings = config.ConnectionStrings; if (connStrings != null) { if (!connStrings.SectionInformation.IsProtected) { if (!connStrings.ElementInformation.IsLocked) { // Protect the section. connStrings.SectionInformation.ProtectSection(provider); connStrings.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); } } } […]

如何在Visual Studio 2010和Windows 7中使用FIPSvalidation的加密算法?

我在Windows 7中启用了FIPS兼容模式,但现在我的代码无法编译,并出现以下错误: Source file ‘whatever.cs’ could not be opened (‘This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.’) 我正在使用SHA1(散列)和TripleDes(加密)加密。 我也尝试过SHA512和AES(256位密钥)。 我不能让项目继续构建,但我需要编译它以使用FIPS兼容算法。

EncryptedXml DecryptDocument方法抛出“Bad Data”exception

我为Encrypt / Decrypt Streams写了一个代码块。 代码在我的本地计算机上运行。 但是当我在网上发布我的代码时,解密函数抛出“坏数据”exception这是我的加密和解密函数 private static MemoryStream EncryptStream(XmlDocument xmlDoc, XmlElement elementToEncrypt, string password) { CspParameters cspParams = new CspParameters(); cspParams.KeyContainerName = password; RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams); RijndaelManaged sessionKey = null; try { if (xmlDoc == null) throw new ArgumentNullException(“xmlDoc”); if (rsaKey == null) throw new ArgumentNullException(“rsaKey”); if (elementToEncrypt == null) throw new […]

C#中的密码加密?

如何在C#中加密和解密密码? 谢谢你的帮助。

RSA:在javascript中加密密码但在C#中无法解密

我想在我的项目中应用RSA加密,但遇到了一些麻烦: 首先,我从http://www.ohdave.com/rsa/下载JavaScripts库,并添加对我的项目的引用; 其次,我已经定义了RSA对象和代码来初始化: internal RSACryptoServiceProvider Rsa { get { if (HttpContext.Cache[“Rsa”] != null) { RSACryptoServiceProvider encryptKeys = (RSACryptoServiceProvider)HttpContext.Cache[“Rsa”]; return encryptKeys; } else { return new RSACryptoServiceProvider(1024); } } set { HttpContext.Cache.Remove(“Rsa”); HttpContext.Cache.Insert(“Rsa”, value); } } public ActionResult SignUp() { this.Rsa = Security.GetRsa(); RSAParameters param= this.Rsa.ExportParameters(true); //this will bind to view TempData[“exponent”] = Util.BytesToHexString(param.Exponent); TempData[“key”] = […]