locked
Error RRS feed

  • Question

  • User1979860870 posted

    Hi

    AsymmetricKeyParameter -  The type or namespace name 'AsymmetricKeyParameter' could not be found (are you missing a using directive or an assembly reference?)

    PublicKeyFactory - The name 'PublicKeyFactory' does not exist in the current context

    RsaKeyParameters - The type or namespace name 'RsaKeyParameters' could not be found (are you missing a using directive or an assembly reference?) 
    public static string EncryptAsymmetric(string password, string Publickey)
            {
                byte[] keyBytes = Convert.FromBase64String(Publickey);
                AsymmetricKeyParameter asymmetricKeyParameter = PublicKeyFactory.CreateKey(keyBytes);
                RsaKeyParameters rsaKeyParameters = (RsaKeyParameters)asymmetricKeyParameter;
                RSAParameters rsaParameters = new RSAParameters();
                rsaParameters.Modulus = rsaKeyParameters.Modulus.ToByteArrayUnsigned();
                rsaParameters.Exponent = rsaKeyParameters.Exponent.ToByteArrayUnsigned();
                RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                rsa.ImportParameters(rsaParameters);
                byte[] plaintext = Encoding.UTF8.GetBytes(password);
                byte[] ciphertext = rsa.Encrypt(plaintext, false);
                string cipherresult = Convert.ToBase64String(ciphertext);
                return cipherresult;
            }

    Thanks

    Thursday, February 4, 2021 1:46 PM

All replies

  • User1120430333 posted

    Look at my reply post to your first post.

    Thursday, February 4, 2021 9:28 PM
  • User303363814 posted

    Pick the first error.  Read the error message.  If you don't understand it then search for the complete error message (you will find that there are tens of thousands of people who have had the exact same error)

    Fix the first error

    Recompile

    Repeat

    Thursday, February 4, 2021 9:36 PM