📄 resultsdecrypter.java
字号:
package abchr.gui;
import abchr.crypto.*;
import java.io.*;
public class ResultsDecrypter {
public static String decrypt(ElGamalPrivateKey key,InputStream input) throws IOException {
Decryptor decryptor=new ElGamalDecryptor(key);
byte[] length=new byte[4];
input.read(length);
//System.out.println("length="+Util.byteArrayToInt(length,0));
byte[] encryptedKey=new byte[Util.byteArrayToInt(length,0)];
input.read(encryptedKey);
byte[] blowfishKey;
blowfishKey=decryptor.decrypt(encryptedKey);
Cipher cipher=new BlowfishCipher(Util.bytesToInts(blowfishKey));
input.read(length);
//System.out.println("length="+Util.byteArrayToInt(length,0));
byte[] encryptedText=new byte[Util.byteArrayToInt(length,0)];
input.read(encryptedText);
byte[] plainText;
try {
plainText=cipher.decrypt(encryptedText);
} catch(IllegalArgumentException e) {
throw new IOException("Data corrupt.");
}
return new String(plainText,0,plainText.length,"UTF-8");
}
public static String decrypt(ElGamalPrivateKey key,File f) throws IOException {
InputStream input=new BufferedInputStream(new FileInputStream(f));
String s=decrypt(key,input);
input.close();
return s;
}
public static ElGamalPrivateKey getKey(InputStream stream) throws IOException {
ObjectInputStream keyInput=new ObjectInputStream(stream);
ElGamalPrivateKey key;
try {
key=(ElGamalPrivateKey)keyInput.readObject();
} catch(ClassNotFoundException e) {
throw new IOException("Invalid file format");
}
keyInput.close();
return key;
}
public static ElGamalPrivateKey getKey(File f) throws IOException {
InputStream stream=new FileInputStream(f);
ElGamalPrivateKey key=getKey(stream);
stream.close();
return key;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -