JOSE_JS JWE The data that encrypted by javascript won't decrypt by go
<p>Server side code for generating public key is:</p>

<pre><code>privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
    return nil
}
publicKey := &amp;privateKey.PublicKey
publicKeyBytes, err := json.Marshal(publicKey)
privateKeyBytes,err:=json.Marshal(privateKey)
</code></pre>

<p>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.</p>

<p>Then the client which is a web browser here encrypts the data by server's public key:</p>

<pre><code>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(/([\[)?(\d+)([,\}\]])/g, "$1\"$2\"$3");
serverPublicKey = JSON.parse(serverPublicKey)
var rsa_key = {
     "n":btoa(serverPublicKey.N).replace(/=/g, ''),
      //Maybe the above line causes the problem.But I couldn't find any other way.
         "e": 65537,
    };
    var cryptographer = new Jose.WebCryptographer();
    cryptographer.setKeyEncryptionAlgorithm("RSA-OAEP");
    cryptographer.setContentEncryptionAlgorithm("A128GCM");
    cryptographer.setContentEncryptionAlgorithm("A128CBC-HS256");
    var public_rsa_key = Jose.Utils.importRsaPublicKey(rsa_key, "RSA-OAEP");
    var encrypter = new JoseJWE.Encrypter(cryptographer, public_rsa_key);
    str="test"
    encrypter.encrypt("sara").then(function(data) {
    $scope.params.Param1=data
    TestService.SendParamToServer($scope.params).then(function(result){
         console.log("success")
    }).catch(function(error){
         console.log("error")
    })
</code></pre>

<p>And then the server tires to decrypt the data just encrypted by the code above:</p>

<pre><code>jweString = string(p.Param1)
jwe, err = jose.ParseEncrypted(jweString)
if err != nil {
    panic(err.Error())
}
data, err := jwe.Decrypt(services.NewSecurityService().GetPrivateKey())
if err != nil {
   // The error is not nil:
   // square/go-jose: error in cryptographic primitive
   panic(err.Error())

}
</code></pre>

<p>But unfortunately we get the following error:</p>

<pre><code>square/go-jose: error in cryptographic primitive
</code></pre>