【发布时间】:2016-09-16 10:24:39
【问题描述】:
为了使其更适用于其他人,我想知道编写代码将加密消息到没有密码就不可能被解密的程度有多现实。我认为最好的方法是制作哈希算法并添加随机性。那么对于代码爱好者来说,编写声音加密有多现实呢?任何工程师都能够破解业余加密算法吗? 编辑:有几个答案讨论了对计算机内存的攻击,这是我很欣赏的有用信息,但我更想知道是否可以直接解密消息。我假设密码分析器无法访问混淆消息的计算机,因为如果他这样做了,他无论如何都可以查看我的源代码并找到解密算法。 这是我的例子:
public class Keys { // hold the methods and information used to lock, unlock, make the key, get the "keypad" after it has been locked, and a static method to change int[] to long[]
// Fields
private String passphrase;
private long[] key;
private long keynum;
private long[] pad;
Random rands = new Random();
// Constructors
public Keys (String passphrase) // makes a key based of the given passphrase
{
this.passphrase = passphrase;
key = keycipher(this.passphrase.toCharArray());
key = keyfix(key);
keynum = key[0];
for (int i=1; i < key.length && key[i] != 0; i=i+1)
if (i <key.length -1 && key[i] == key[i+1])
keynum = keynum *key[i] +1;
else if (i+1 < key.length)
keynum = keynum * key[i] - key[i+1];
else
keynum = keynum * key[i] -1;
}
/**
*used to lock and save a message in the pad field
* @param message2lock the input which will be locked using the key and saved as the field pad
*/
public void lock (String message2lock)
{
Message2Num holenums = new Message2Num(message2lock); // message2nums converts inout string to number []
holenums.step1(); //uses custom cipher to change each character to a long
long[] hole =new long[holenums.step2().length];
int t =0;
for(int g : holenums.step2())
/* // Step 2 uses the cipher from step 1 and hides it in random numbers by doubling the array length
then making every even number in the array length a random number and every odd number the last random number
minus the original cipher number
*/
{
hole[t] = (long) g;
t++;
}
hole = this.padding(hole);
double p = (double) keynum;
p = 3* Math.cos(p);
long z = (long) p;
for ( int i =0; i< hole.length; i++)
hole[i] = hole[i] * keynum + z;
hole = Message2Num.addcommas(hole);
pad =hole;
}
【问题讨论】:
-
“这有多安全” ...
private String passphrase;...不是很安全。 (stackoverflow.com/questions/8881291/…) -
"Schneier's Law": “任何人,从最无知的业余爱好者到最优秀的密码学家,都可以创建自己无法破解的算法。”所以答案是编写自己的加密代码是不现实的。最好的建议是使用当前标准:AES(高级加密标准)。要将密码转换为密钥,请使用 PBKDF1(基于密码的密钥派生函数 2)。
-
这种事情千万不要在真实系统上做,请坚持使用已经接受安全的官方函数,除非你真的知道自己在做什么,否则不要使用自己的函数进行安全!
-
@Tom 谢谢!所以我使用 JTextField 来获取字符串,如果不是拉字符串我拉 String.tochar 或任何方法,它会更安全还是字符串问题使 JTextFields 不安全?
-
如果您想从使用 Swing 的用户那里获取密码,请使用
JPasswordField。
标签: java encryption hash password-encryption