Data encryption using Base64 PublicKey & decryption using Base64 PrivateKey #5703
Replies: 2 comments
|
The problem is that Rather than have you write the stripping code, I've added it to the API. On the next update you'll be able to write: InputStream publicStream = Display.getInstance().getResourceAsStream(MyApp.class, "/Base64TestPublicKey.pem");
PublicKey publicKey = PublicKey.fromPem(Util.readInputStream(publicStream));
InputStream privateStream = Display.getInstance().getResourceAsStream(MyApp.class, "/Base64TestPrivateKey.pem");
PrivateKey privateKey = PrivateKey.fromPem(Util.readInputStream(privateStream));The rest of your code can remain unchanged. In the meantime, on the current release you can strip the armor yourself. Note you can't just decode the whole file private static byte[] pemToDer(InputStream is) throws IOException {
String pem = new String(Util.readInputStream(is), "UTF-8");
StringBuilder b = new StringBuilder();
for (String line : Util.split(pem, "\n")) {
line = line.trim();
if (line.length() == 0 || line.startsWith("-----")) {
continue;
}
b.append(line);
}
return Base64.decode(b.toString().getBytes("UTF-8"));
}Then One thing to check on the private key if you go that route: it must be PKCS#8 ( |
|
Thanks. Changing to fails with this exception |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Data encryption & decryption works with Public & Private Keys in raw binary formats like these
BinaryKeys.zip using this test case
Changing keys to Base64 formats like these
Base64Keys.zip
throws the following InvalidKeyException
These Base64 keys formats are already working in backend. How can they also work in Codename One app?
All reactions