为了更好地理解RSA,我一直在使用GunPG 1.4的源代码,特别是rsa.c文件中的RSA实现.正如标题所说,我无法弄清楚填充的位置.
因此,通常在RSA中,填充在加密之前完成,并在解密期间取消.加密首先从我们看到的第409行开始
int
rsa_encrypt( int algo, MPI *resarr, MPI data, MPI *pkey )
{
RSA_public_key pk;
if( algo != 1 && algo != 2 )
return G10ERR_PUBKEY_ALGO;
pk.n = pkey[0];
pk.e = pkey[1];
resarr[0] = mpi_alloc( mpi_get_nlimbs( pk.n ) );
public( resarr[0], data, &pk );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这似乎很容易,它将数据提供给第220行的"公共"功能.公共负责计算重要的(c = m ^ e mod n)过程.这一切看起来像:
static void
public(MPI output, MPI input, RSA_public_key *pkey )
{
if( output == input ) { /* powm doesn't like output and input the …Run Code Online (Sandbox Code Playgroud) 我有以下问题:在我的ASP.NET MVC应用程序中,我想在我的数据库中存储一些键/值设置.其中一些键/值设置包含密码,我想加密密码以保护它们.
我无法对密码进行哈希处理,因为我需要一些密码才能在远程SMTP服务器上进行验证.
在MSDN上,我发现了一篇关于使用"受保护的配置提供程序"保护配置设置的文章,但我不想将该设置存储在我的web.config文件中.
我考虑使用DpapiProtectedConfigurationProvider,它使用一些机器和用户特定属性作为加密密钥,但是此提供程序仅用于XML配置节点.
另一篇 MSDN 文章是关于ProtectedData类的,但这种方法真的安全吗?
那么,在C#应用程序中存储密码的最佳方法是什么?
我还阅读了以下其他问题,但我找不到解决方案: 问题1,问题2,问题3
问候
我正在比较pycrypto和cryptography.io库中的Python实现.
from cryptography.hazmat.primitives.ciphers import Cipher, modes, algorithms
from cryptography.hazmat.backends import default_backend # http://cryptography.io
from Crypto.Cipher import AES # http://pycrypto.org
key = b'Sixteen byte key'
iv = b'Sixteen byte ivv'
cipher1 = AES.new(key, AES.MODE_CFB, iv)
cipher2 = Cipher(algorithms.AES(key), modes.CFB(iv), default_backend())
plaintext = b"Plaintext"
print(cipher1.encrypt(plaintext))
print(cipher1.decrypt(plaintext))
print(cipher2.encryptor().update(plaintext))
print(cipher2.decryptor().update(plaintext))
Run Code Online (Sandbox Code Playgroud)
MWE打印:
b'\xe4\xb4\xeb\xe3Si\x9ap\xee'
b'7\xda\x98\xee\x05\xe4\xa0\xc7,'
b'\xe4"\xd4mo\xa3;\xa9\xe0'
b'\xe4"\xd4mo\xa3;\xa9\xe0'
Run Code Online (Sandbox Code Playgroud)
为什么输出不同?
python encryption cryptography encryption-symmetric pycrypto
我在一家Web开发公司工作,当应用程序未连接到Internet时负责保护应用程序或任何其他内容的安全,这意味着HTTPS不适用标准登录协议。
我为个人服务的公司本身在互联网连接不好的情况下申请“在路上”。出于每个人都可以理解的原因,用户必须能够“锁定”应用程序,并且还必须能够解锁。最好使用他们用于在线时登录的密码(当与Web服务器在线时,它们会获得一个安全的cookie进行身份验证)。
现在,我需要一种方法来检查密码,而又不会让黑客轻易地查看websql/indexdb/local存储并在那里找到它。将其存储为简单的哈希值很容易被黑客入侵。
我曾想过将其存储为盐,但是被黑客入侵只是时间问题,还考虑了哈希部分密码(例如最后4个字符)和盐。万一它确实变成彩虹,他们只会解锁应用程序而没有密码。
我似乎找不到真正和/或标准化的方法来保护离线HTML5应用程序。但是,有没有最佳实践呢?
另一个问题是脱机存储本身中数据的安全性,以便只有应用程序才能读取它。我可以想出使数据“不可读”的方法,但是我可以想出的所有方法来安全地存储记录,我还可以想出一种方法来破解它。因此,也欢迎在该领域提供任何建议。
我被告知使用AES256加密一些表格数据(字符串),并给了一个很好的库,已经完成了所有这些.我只是想确保我更好地理解它并学习一些关于加密的知识,因为它不是我喜欢的东西.在我这样做的时候,我在一些网站上看到了一个测试,它说要调用它Cipher.getMaxAllowedKeyLength("AES")来为你提供最大的密钥长度.结果是128.
无论如何,最大允许密钥长度是128,这是否意味着我不能使用AES256?还是那些无关的?
编辑:我应该提到我知道如何获得无限制的政策文件来改变这一点,我只是想在继续之前更好地理解整个交易.
我正在构建一个可移植的库目标Windows 8.1.我需要加密密码才能通过http连接发送密码.问题是System.Security.Cryptography在便携式库中不可用.
我能找到的唯一解决方案是PCL Contrib,但是将它添加到我的项目中似乎太过于笨重.我也得到了一些PCL Contrib我无法解决的运行时异常.
我确信那里必须有一个简单的解决方案,但我找不到任何不使用的解决方案System.Security.Cryptography.有谁知道可以在便携式库中使用的简单易用的加密?
我需要以这样的URL传递加密格式的数据,
http://localhost:8080/app/{encrypted_data}
那么,是否有编码器中不包含正斜杠(/)的编码器?
请注意:我不想手动从编码数据中用另一个字符替换'/'.
.................................................. .................................................. ..........
编辑:Oleg Estekhin评论使用Base64 URL安全编码工作正常,我只是在这里添加一个例子.
示例:编码:
String str = "subjects?_d=1";
byte[] bytesEncoded = Base64.encodeBase64URLSafe((str.getBytes()));
Run Code Online (Sandbox Code Playgroud)
解码:
Base64 decoder = new Base64(true);
byte[] decodedBytes = decoder.decode(new String(bytesEncoded));
System.out.println(new String(decodedBytes));
Run Code Online (Sandbox Code Playgroud)
输出:
c3ViamVjdHM_X2Q9MQ
subjects?_d=1
Run Code Online (Sandbox Code Playgroud) 我对BouncyCastle和pgp很新.我在互联网上看过很多文章和样本.几乎每个加密样本都包含下面剪切的代码
if (armor)
out = new ArmoredOutputStream(out);
Run Code Online (Sandbox Code Playgroud)
似乎我的本地测试通过了护甲和无护甲.我用google搜索但发现很少有用,而ArmoredOutputStream的javadoc只显示这是基本的输出流.
那么有什么区别以及何时使用它?
完整的代码示例:
public static void encryptFile(String decryptedFilePath,
String encryptedFilePath,
String encKeyPath,
boolean armor,
boolean withIntegrityCheck)
throws Exception{
OutputStream out = new FileOutputStream(encryptedFilePath);
FileInputStream pubKey = new FileInputStream(encKeyPath);
PGPPublicKey encKey = readPublicKeyFromCollection2(pubKey);
Security.addProvider(new BouncyCastleProvider());
if (armor)
out = new ArmoredOutputStream(out);
// Init encrypted data generator
PGPEncryptedDataGenerator encryptedDataGenerator =
new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, withIntegrityCheck, new SecureRandom(),"BC");
encryptedDataGenerator.addMethod(encKey);
OutputStream encryptedOut = encryptedDataGenerator.open(out, new byte[BUFFER_SIZE]);
// Init compression
PGPCompressedDataGenerator compressedDataGenerator = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
OutputStream compressedOut = compressedDataGenerator.open(encryptedOut);
PGPLiteralDataGenerator …Run Code Online (Sandbox Code Playgroud) 我想AES/CBC/Nopadding在c#Windows Phone 8应用程序中解密加密Sting .我的字符串在IsolatedSorage.我粘贴了垃圾桶HERE.
从这篇文章我使用AesManaged类来解密.但是如何设置填充,NoPadding因为默认情况下填充设置为PKCS7从这里开始.
string fileName = "titlepage.xhtml";
if (fileStorage.FileExists(fileName))
{
IsolatedStorageFileStream someStream = fileStorage.OpenFile(fileName, System.IO.FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(someStream))
{
str1 = reader.ReadToEnd();
MessageBox.Show(str1);
try
{
string text = Decrypt(str1, "****************", "****************");
MessageBox.Show(text);
}
catch (CryptographicException cryptEx)
{
MessageBox.Show(cryptEx.Message, "Encryption Error", MessageBoxButton.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "General Error", MessageBoxButton.OK);
}
}
}
public string Decrypt(string dataToDecrypt, string password, …Run Code Online (Sandbox Code Playgroud) 我有一些Key和Initial Vector,我在.NET应用程序中用于加密.让我们说它们是:
Key = 0x0102030405060708090A0B0C0D0E
IV = 0xA1A2A3A4A5A6A7A8A9AAABACADAE
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我想在SQL Server上执行加密(不在应用程序中),但在应用程序中解密数据.我以为我可以在数据库中创建临时对称密钥并执行加密:
CREATE SYMMETRIC KEY #TempKey
WITH ALGORITHM = AES_128
, IDENTITY_VALUE = ???
, KEY_SOURCE = ???
ENCRYPTION BY PASSWORD = 'Pa$$w0rd';
OPEN SYMMETRIC KEY #TempKey
DECRYPTION BY PASSWORD = 'Pa$$w0rd';
SELECT EncryptByKey(Key_Guid('#TempKey'), 'Secret Data');
CLOSE SYMMETRIC KEY #TempKey;
DROP SYMMETRIC KEY #TempKey;
Run Code Online (Sandbox Code Playgroud)
但我不知道我应该提供什么作为IDENTITY_VALUE和KEY_SOURCE在DB和我的应用程序之间有一个"共享"键.
更新2014-07-07
我想提供一些问题的背景知识.
首先,我正在使用EF Code First方法,当我需要执行一些数据库更新时,我使用Code First Migrations,我想进一步使用这种基于纯迁移的方法.不幸的是,正如在EF Code First迁移中使用自定义逻辑的问题中找到的那样,无法在Up或Down方法中获取当前的SqlConnection和SqlTransaction .我唯一的方法 - 使用Sql方法执行自定义SQL查询.
在下一个数据库更新中,我想要在一列中加密数据.加密应该满足两个条件:(1)数据应该在客户端应用程序中解密(不在SQL Server端),(2)对称密钥应该以加密形式存储在客户端应用程序中,描述应该是使用密钥容器中的非对称密钥完成.不幸的是,这使得CRL UDF在这里无用 - 当我尝试在UDF中获取基于密钥容器的密钥时,我得到一个权限异常: …
encryption ×10
aes ×3
c# ×3
java ×3
security ×2
.net ×1
asp.net-mvc ×1
bouncycastle ×1
cryptography ×1
encoding ×1
gnupg ×1
html5 ×1
offline ×1
openpgp ×1
padding ×1
pgp ×1
pycrypto ×1
python ×1
rsa ×1
sql-server ×1