Cryptography 我的密码解密类有多安全?
我是任何解密的初学者。我写了一个我认为应该很安全的类。你能对我如何改进算法提出建设性的批评吗Cryptography 我的密码解密类有多安全?,cryptography,encryption,password-protection,Cryptography,Encryption,Password Protection,我是任何解密的初学者。我写了一个我认为应该很安全的类。你能对我如何改进算法提出建设性的批评吗 package main; import java.util.Random; public class Main { public static void main(String[] args) { //we will be playing around with this string new Main("1234567890abc"); } priv
package main;
import java.util.Random;
public class Main {
public static void main(String[] args) {
//we will be playing around with this string
new Main("1234567890abc");
}
private Random rnd;
private byte[] randoms;
/**
* Starts up RNG
* Prints out a test
*/
public Main(String password) {
//random long generated from the password
long randomLong = randomNumber(password);
//Random class using randomLong as seed
rnd = new Random(randomLong);
randoms = new byte[password.length()];
//Array of random bytes generated with rnd
rnd.nextBytes(randoms);
System.out.println(randomNumber(password));
String cryped = encrypt(password);
String decryped = decrypt(cryped);
System.out.println(cryped);
System.out.println(decryped);
}
/**
* Encrypts the password.
*/
private String encrypt(String password) {
char[] chars = password.toCharArray();
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) (chars[i] + randoms[i]);
}
return String.valueOf(chars);
}
/**
* Decrypts an allready encryped password.
*/
private String decrypt(String crypted) {
char[] chars = crypted.toCharArray();
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) (chars[i] - randoms[i]);
}
return String.valueOf(chars);
}
/**
* Finds a random number BASED ON PASSWORD
*/
private long randomNumber(String password)
{
char[] chars = password.toCharArray();
long number = 0;
for (char c : chars) {
number += c;
}
number *= chars.length;
return number;
}
}
packagemain;
导入java.util.Random;
公共班机{
公共静态void main(字符串[]args){
//我们将玩这根绳子
新干线(“1234567890abc”);
}
私有随机rnd;
私有字节[]随机数;
/**
*启动RNG
*打印测试结果
*/
公用主(字符串密码){
//由密码生成的随机长密码
long randomLong=随机数(密码);
//使用randomLong作为种子的随机类
rnd=新随机(随机长);
randoms=新字节[password.length()];
//使用rnd生成的随机字节数组
rnd.下一个字节(随机);
System.out.println(随机数(密码));
字符串cryped=加密(密码);
String decryped=解密(cryped);
系统输出打印LN(cryped);
System.out.println(取消键入);
}
/**
*加密密码。
*/
私有字符串加密(字符串密码){
char[]chars=password.toCharArray();
for(int i=0;i
该类是用Java编写的,但任何人都应该可读。在多个方面都被严重破坏
假设攻击者知道
encrypt(p1)
和encrypt(p2)
。然后他可以计算encrypt(p1)-encrypt(p2)
,这与p1-p2
相同为什么不把代码放在这里?为了可读性,指数化。。。那是家庭作业吗?如果不是,为什么不使用java.security.*?它不是家庭作业,我也不必在任何地方使用它。当然不是想打破你的泡沫,但人们花了一生的时间来编写加密安全软件。在现实世界中,当有人粗暴地强迫你的数据库时,创建一个55行的类并不能减少它。如其他人所说,如果您有兴趣学习,请使用现有类或读入开源加密包。是否可以将您的代码从pastebin复制到此处?这样一来,当pastebin过期时,你的问题就有意义了……据我所知,什么都没有:+1当你写下那1000'000个数字时,我想我会写一个粗体forcer:结果是,最多16个字符,有9642种不同的可能性:非常有限:-)brute强制他的密码存储的主要问题是如何识别您是否成功。我假设他实际上没有将其用于密码存储,因为他在那里有解密功能,而这只适用于他从