我是密码学的新手。
我想在java中生成RSA密钥并将其写入文件。稍后我想从该文件中读取并取回 RSA 密钥。
密钥生成和写入文件的代码:
public void generate() throws Exception{
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair kpair = kpg.genKeyPair();
byte[] publicKeyBytes = kpair.getPublic().getEncoded();
FileOutputStream fos = new FileOutputStream("publicKey");
fos.write(publicKeyBytes);
fos.close();
}
Run Code Online (Sandbox Code Playgroud)
读取和取回 RSA 公钥的代码:
public static Key getKeyFromFile(String fileName) throws Exception{
Key pk = null;
File f = new File(fileName);
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
byte[] keyBytes = new byte[(int)f.length()];
dis.readFully(keyBytes);
dis.close();
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
pk = kf.generatePublic(spec);
return …Run Code Online (Sandbox Code Playgroud) 我想将一个数组中的点与另一个数组中的点进行比较并找到最接近的一对。到目前为止,我遇到的都是单个数组。我不想比较同一数组中的点。暴力算法可以工作,但速度太慢。是否有使用分而治之方法的算法或实现?
编辑1:点被定义为地球表面上的一对(纬度,经度)。
是否可以通过telnet从一个Android模拟器拨打另一个?
例如,我在屏幕上打开了两个模拟器5554和5556.我可以使用命令:gsm call 5554从5554通过telnet接收来电.
是否可以拨打5554到5556的电话,反之亦然?