Server side code for generating public key is:
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return nil
}
publicKey := &privateKey.PublicKey
publicKeyBytes, err := json.Marshal(publicKey)
privateKeyBytes,err:=json.Marshal(privateKey)
The private key is a singleton stored in memory at server side and the public key is another singleton which is being returned to the clients requesting it.
Then the client which is a web browser here encrypts the data by server's public key:
cookieParts=document.cookie.split('pk=')
if(cookieParts.length==1)
{
serverPublicKey= unescape(cookieParts[0].split(';')[0].toString())
}
else
{
serverPublicKey= unescape(cookieParts[1].split(';')[0].toString())
}
serverPublicKey =serverPublicKey.replace(/([[