whimsical1987 0 Newbie Poster

I am trying to implement a protocol that includes cryptography. What I am supposed to do is encrypt a combination of two public keys and a message. Although I have the message in String format I don’t have the public keys in string format. I am making use of getpublic class that Returns a reference to the public key component of this key pair.. However I want to store this getpublick key value in a string format. So can any please help me in storing the publickey value as a string ?

keyGenEn =  KeyPairGenerator.getInstance("RSA");
       keyGenSi  = KeyPairGenerator.getInstance("RSA");
       keyGenEn.initialize(1024);
       keyGenSi.initialize(1024);
       key1 = keyGenEn.generateKeyPair();
       key2 = keyGenSi.generateKeyPair();
     
       PrivateKey priven = key1.getPrivate();
       PublicKey puben = key1.getPublic();
       //Cathy c1 = new Cathy();
        
       PrivateKey privsi = key2.getPrivate();
       PublicKey pubsi = key2.getPublic();

       byte[] alicepublicen = puben.getEncoded();
       String messageToEncryptCredential = "Alice credential";
       System.out.println(messageToEncryptCredential);

       byte[] alicepublicsi = pubsi.getEncoded();
       String MessageAlice = alicepublicsi.toString() + alicepublicen.toString() + messageToEncryptCredential;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.