我已经读过用Java加密整数和使用密码短语使用DES加密了。
我所需要的只是一个简单的Encrypter,它将一个12位数字转换为一个12位数,并有以下约束:
在浏览了文献之后,我随身带着这段代码。
public void mytestSimple(long code, String password) throws Exception {
SecretKey key = new SecretKeySpec(password.getBytes(), "DES");
Cipher ecipher = Cipher.getInstance("DES");
ecipher.init(Cipher.ENCRYPT_MODE, key);
System.out.println(ecipher.getOutputSize(8));
byte[] encrypted = ecipher.doFinal(numberToBytes(code));
System.out.println(encrypted + "--" + encrypted.length);
Cipher dcipher = Cipher.getInstance("DES");
dcipher.init(Cipher.DECRYPT_MODE, key);
byte[] decrypted = dcipher.doFinal(encrypted);
System.out.println(bytesToNumber(decrypted) + "--" + decrypted.length);
}
public void testSimple() throws Exception {
mytestSimple(981762654986L, "password");
}我遇到了一些问题
*我在下面添加的答复*
我已经添加了一个答案,这是一个从标准Java密钥生成逻辑中提取的40位RSA。我还得处理边缘的案子。我将接受这个答案,并投票给"Tadmas“,我认为他会带我找到答案。有人能告诉我我的算法是否会弱/可攻击吗?
https://stackoverflow.com/questions/858476
复制相似问题