N
N
Nogok2017-05-19 19:37:00
Java
Nogok, 2017-05-19 19:37:00

I am working on a project related to the DSA algorithm. Does anyone know how to send the public key to the server?

I create a key pair using java.security.KeyPair, pull the public key, but it is
a) Just huge, despite all attempts to reduce it, the minimum Json string is 3300+ characters
b) It is not parsed back into the key, because PublicKey -- class, as I understand it
Here is the exception:
java.lang.RuntimeException: Unable to invoke no-args constructor for interface java.security.PublicKey. Register an InstanceCreator with Gson for this type may fix this problem.
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:210)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2017-05-19
@zagayevskiy

In general, PublicKey implements Serializable. You can serialize it, then stuff it into Base64, and transfer it to JSON.
BUT
Why are you even doing this? If the key is transmitted in the clear, then an attacker can organize MiTM and all your encryption goes to the forest.

L
Labunsky, 2017-05-20
@Labunsky

a) Pretty weird. Typically, keys no larger than 3072 bits are used, which, even when over-encoded in base64, gives 512 characters. The pure byte representation is, accordingly, limited to 384 bytes. Might be worth looking at the JSON key wrapping algorithm - the problem is probably in there somewhere.
b) To create a new PublicKey, just parse the public key "y" as a BigInteger and pass it to the standard constructor along with the rest of the public parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question