I have a below cSharp code that does encryption with a public key. I was asked to do the same with Javascript/NodeJS. Is this even possible to do it? This is the first time I doing any kind of encryption. Please help me understanding what are the difficulties I may face if I proceed for this. Are there any plugins to do this?
public static string EncryptAsymmetric(string encryptText, string publicKey)
{
byte[] buffer;
bool fOAEP = false;
byte[] bytes = Encoding.UTF8.GetBytes(encryptText);
using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
{
provider.FromXmlString(publicKey);
buffer = provider.Encrypt(bytes, fOAEP);
}
return Convert.ToBase64String(buffer);
}
Thanks in advance