首先声明,我从未学过密码学,我所知道的一切都只是基本概念。
我们正在寻找一种快速简便的方法,使用密码加密一些数据(存储到数据库中)。 我知道“最安全”的算法是AES,但对于我们来说可能太复杂了,而且我知道它需要我们获得美国政府的授权等。
我们考虑了这个(简单的)算法,它让我想起了一种“一次性密码本”(但我可能错了)。 (它没有用任何特定的语言...只是一个想法 :))
// The string we need to encrypt
string data = "hello world";
// Long string of random bytes that will be generated the first time we need to encrypt something
string randomData = "aajdfskjefafdsgsdewrbhf";
// The passphrase the user selected
string passphrase = "foo";
// Let's generate the encryption key, using randomData XOR passphrase (repeating this one)
string theKey = "";
j = 0;
for(i = 0; i < randomData.length; i++)
{
theKey += randomData[i] ^ passphrase[j];
j++;
if(j == passphrase.length) j = 0;
}
// Encrypt the data, using data XOR theKey (with theKey.length >= data.length)
string encryptedData = "";
for(i = 0; i < data.length; i++)
{
encryptedData += data[i] ^ theKey[i];
}
在磁盘上,我们只会存储随机数据和加密数据。每次都会要求用户输入密码。
像这样的算法有多安全? 除了暴力破解外,还有其他方法可以破解吗?我觉得统计分析不可能奏效,是吗? 它与一次性密码本一样安全吗?
谢谢!