java - java中如何将String转换为Key

标签 java cryptography

我想将字符串转换为键类型。

BufferedReader br = new BufferedReader(new FileReader(publicKeyFile));
String publicKey = br.readLine();//(Key) keyIn.readObject();
br.close();

Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.WRAP_MODE, publicKey);

cipher.init(Cipher.WRAP_MODE, publicKey); 需要具有接口(interface) Key 的类型的 publickey .

那么如何将字符串转换为键?

最佳答案

使用KeyFactory根据KeySpec创建您需要的Key。

关于java - java中如何将String转换为Key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23500790/

相关文章:

java - 找不到符号方法initCause

java - spring batch 配置元素不可达

java - Eclipse : Used testNG 7 without built with maven ? 类路径问题

node.js - 如何在 Electron 中使用加密

c++ - 用于 RSA PKCS#1( key 生成)的 C++ 中的加密安全 RNG

java.lang.ClassCastException 套接字 readObject

java - 如何找到一些 GPS 点的中点/坐标?

iOS AES256解密

c# - 将 Java 加密代码转换为 C#

.net - 使用 System.Text.UnicodeEncoding.Unicode.GetString(byte[]) 反向编码字节数组时间歇性失败