@@ -0,0 +1,1385 @@
+package backend;%0A%0Aimport java.math.BigInteger;%0Aimport java.security.KeyFactory;%0Aimport java.security.KeyPair;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.interfaces.RSAPublicKey;%0Aimport java.security.spec.InvalidKeySpecException;%0Aimport java.security.spec.RSAPublicKeySpec;%0A%0A/*%0A * To serialize and deserialize the key%0A */%0Apublic class Serialization %7B%0A%09public Serialization()%7B%0A%09%09%0A%09%7D%0A%09%0A%09/**%0A%09 * return string of %221234%7C5678%22 %0A%09 * where 1234 is publicKeyModulus and 5678 is publicKeyExponent%0A%09 * @param kp keypair%0A%09 * @return serialized keystring%0A%09 */%0A%09public String SerializePublicKey(KeyPair kp)%7B%0A%09%09RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();%0A%09%09return publicKey.getModulus().toString() + %22%7C%22 +%0A%09%09    publicKey.getPublicExponent().toString();%0A%09%7D%0A%09%0A%09/**%0A%09 * Deserialize keystring to RSAPublicKey %0A%09 * @param keyString%0A%09 * @return RSAPublicKey%0A%09 */%0A%09public RSAPublicKey DeserializePublicKey(String pubKeyString)%7B%0A%09%09String %5B%5DParts = pubKeyString.split(%22%5C%5C%7C%22);%0A%09%09RSAPublicKeySpec Spec = new RSAPublicKeySpec(%0A%09%09        new BigInteger(Parts%5B0%5D),%0A%09%09        new BigInteger(Parts%5B1%5D));%0A%09%09RSAPublicKey pubkey = null;%0A%09%09try %7B%0A%09%09%09pubkey = (RSAPublicKey) KeyFactory.getInstance(%22RSA%22).generatePublic(Spec);%0A%09%09%7D catch (InvalidKeySpecException %7C NoSuchAlgorithmException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return pubkey;%0A%09%7D%0A%09%0A%0A%7D%0A

add function for serialize and deserialize key