我已经使用以下功能生成了私钥-
public static String getPrivateKey() {
KeyPairGenerator keyPairGenerator;
KeyPair keyPair = null;
try {
keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048);
keyPair = keyPairGenerator.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Base64.getMimeEncoder().encodeToString( keyPair.getPrivate().getEncoded());
我正在尝试使用下面的方法将其设置为我的cookie-
Cookie ck = new Cookie("privatekey", privateKey);// creating cookie object
ck.setMaxAge(120);
response.addCookie(ck);// adding cookie in the response
我遇到了错误。密钥本身是字符串格式。我怎样才能做到这一点?我需要将其更改为某种格式吗?
An invalid character [13] was present in the Cookie value
生成的我的私钥如下所示-
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCrQC7J4ZvuXi9u8nK+BLGM5PeP
FOeirNatorzG1EN63V09O2GquR+/OEUI8JesERlf+OUBOo4tjO7O1dgnoZMJUkxwhS5zaCooKkl1
1y728sA4//eHhIjpsNdDQkW3a4NKHo1w5zigcgG08Uz9aLdfy/VlK3mFB8RGliAxUvNzSw+zzkpw
rEEMdIEWYJm9U73+2giESGqRJA8zDIRJ5nSsG3PNuA05K/DZSR/103R0bsZ4BlcinSt5zKmRH5vt
+srX/u8tLX/pF+w5G1S/yzoP3CrP/AtLrEB6Ts5ZmE7Pj4IFdcY2HfNpphbEKCFbqk5E0EkarZZD
JFujnS6PqehtAgMBAAECggEAPYF1zIg9KuWk/6IQV/Lzmfj6eOc3MpQFHqPeTUMbYVt0C3PyZhDL
ODCLiuRudRxHEtMf3MsdGXsOojbnxYQgfS6Tya3ruwNkcLyPWcWJVqRlKZO1YXTWf6hGCCAbTf9N
TiefATfqfKW1uzkXP8SGZ9+nKUjuAjuB4SA2O8DhMzzhfpwXPHmuWRk58llBfZe8RJn1sO0wUztr
BRSvxRpUChBY2xrdMQFIQOnR9qa93Mx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