RSA encryption and decryption for special characters (àâäèéêë)

Discussão em 'Angular' iniciado por chaitanya reddy, Março 18, 2025.

  1. I am using Angular to encrypt the payload with publickey

    publicKey: string = `-----BEGIN PUBLIC KEY-----

    -----END PUBLIC KEY-----`;
    let encryptedCredential = {};
    const rsa = Forge.pki.publicKeyFromPem(this.publicKey);
    Object.keys(empDetails).forEach(keyElement =>{
    encryptedCredential[keyElement] = Forge.util.encode64(rsa.encrypt(empDetails[keyElement].toString()));


    in the backend using dotnet where private key is stored in the server

    backend code:

    RSACryptoServiceProvider rsaCryptoServiceProvider = new RSACryptoServiceProvider();
    using (TextReader privateKeyStringReader = new StringReader(File.ReadAllText(System.Web.HttpContext.Current.Request.MapPath("~\\RSA\\rsakey.pem"))))
    {
    AsymmetricCipherKeyPair pemReader = (AsymmetricCipherKeyPair)new PemReader(privateKeyStringReader).ReadObject();
    RSAParameters rsaPrivateCrtKeyParameters = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)pemReader.Private);

    rsaCryptoServiceProvider.ImportParameters(rsaPrivateCrtKeyParameters);
    }
    var decryptedBytes = rsaCryptoServiceProvider.Decrypt(Convert.FromBase64String(cipherText), false);
    return Encoding.UTF8.GetString(decryptedBytes, 0, decryptedBytes.Length);


    when using the special characters in words, the decryption is not working properly like the text demoé is decrypted to demo�

    Kindly let me know if there is any other to handle such scenarios.

    Thanks in advance!!

    Continue reading...

Compartilhe esta Página