Skip to content

Error using SHA256Managed when create the instance. this work fine in .net31, project server netcoreapp3.1 y shared netstandard2.1 #40080

Closed

Description

@apayero
using System;
using System.Security.Cryptography;
using System.Text;

namespace myNameSpaces
{
    public class Encriptar
    {
        public static string EncriptaPassWord(string Password)
        {
            try
            {
                SHA256Managed hasher = new SHA256Managed();

                byte[] pwdBytes = new UTF8Encoding().GetBytes(Password);
                byte[] keyBytes = hasher.ComputeHash(pwdBytes);

                hasher.Dispose();
                return Convert.ToBase64String(keyBytes);
            }
            catch (Exception ex)
            {
 
                throw new Exception(ex.Message, ex);
            }
        }  
    }
}

Note: Edited for clarity

Activity

  1. Tratcher commented on Jul 29, 2020

    @Tratcher
    Member

    What's the error?

  2. javiercn commented on Jul 29, 2020

    @javiercn
    Member

    @apayero thanks for contacting us.

    This seems like a runtime issue. We'll transfer it there so that they can give you a faster and better answer.

    Are you by any chance using Blazor WebAssembly? I believe there is an issue in the runtime regarding Cryptography when running on WebAssembly.

  3. transferred this issue fromdotnet/aspnetcoreon Jul 29, 2020
  4. added
    untriaged
    on Jul 29, 2020
  5. Dotnet-GitSync-Bot commented on Jul 29, 2020

    @Dotnet-GitSync-Bot
    Collaborator

    I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

  6. GrabYourPitchforks commented on Jul 30, 2020

    @GrabYourPitchforks
    Member

    @apayero Please include the text and stack trace of the exception you're seeing. We need this information in order to assist you further. Thank you!

  7. apayero commented on Aug 1, 2020

    @apayero
    Author

    @apayero Please include the text and stack trace of the exception you're seeing. We need this information in order to assist you further. Thank you!

    Originally posted by @GrabYourPitchforks in #40080 (comment)

    Hi, the stackTrace only say "string {get; ].
    that is all.

    and _message: The type initializer for 'Crypto' threw an exception.'

    best regards.

  8. apayero commented on Aug 1, 2020

    @apayero
    Author

    @apayero Please include the text and stack trace of the exception you're seeing. We need this information in order to assist you further. Thank you!

    @GrabYourPitchforks

    Hi, the stackTrace only say "string {get; ].
    that is all.

    and _message: The type initializer for 'Crypto' threw an exception.'

    best regards.

  9. apayero commented on Aug 1, 2020

    @apayero
    Author

    @javiercn exactly I invoke the method from Webassembly.

    the stackTrace only say "string {get; ].
    and _message: The type initializer for 'Crypto' threw an exception.'

    best regards.

  10. GrabYourPitchforks commented on Aug 1, 2020

    @GrabYourPitchforks
    Member

    Is there an InnerException in the exception you're seeing? What kind of project is this - console, WinForms, webassembly, something else? Do you have a standalone repro app we can run?

  11. vcsjones commented on Aug 1, 2020

    @vcsjones
    Member

    exactly I invoke the method from Webassembly.

    This looks like #40076 then.

  12. GrabYourPitchforks commented on Aug 2, 2020

    @GrabYourPitchforks
    Member

    Duplicate of #40076.

  13. apayero commented on Aug 2, 2020

    @apayero
    Author

    @GrabYourPitchforks @javiercn
    thanks I wait then for the #40076, because is a WebAssembly Project.

  14. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Securityuntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions