For a homework assignement I need to encrypt data with a private key and decrypt it with a public key. I am using JSEncrypt and it is encrypting my data, but when I try do decrypt it, it is returning false. It is an assignement about digital signatures.
I tried to switch it around and encrypt is with my public key, this actually worked, but I don't want to do it this way.
(I am encrypting in a different function, not in the same function as where I am decrypting)
//encrypting
var encrypt = new JSEncrypt({
default_key_size: 1024,
default_public_exponent:"010001"
});
this.hashedvalue = sha256(this.selectedPost.value);
encrypt.setKey(val.privateKey);
var encoded = encrypt.encrypt(this.hashedvalue);
//decrypting
var decrypt = new JSEncrypt({
default_key_size: 1024,
default_public_exponent:"010001"
});
decrypt.setKey(val.postUser.publicKey);
var hashedvalue = sha256(val.value);
var decoded = decrypt.decrypt(val.encryptedvalue);
//returns false
console.log(decoded);
console.log(hashedvalue);