Error when signing a Hash on SHA256 using Digital Certificate

3

Returning Invalid Algorithm Specified error, when will it be signed, how to proceed?

 Dim data = Encoding.UTF8.GetBytes(Me.txtCNPJEmpresa.Text + Me.txtCNPJSoftwareHouse.Text)
 Dim csp As RSACryptoServiceProvider = DirectCast(Certificado.PrivateKey, RSACryptoServiceProvider)

 Dim sha As SHA256 = SHA256Managed.Create()
 Dim hash As Byte() = New Byte() {}
 hash = sha.ComputeHash(data)

 Dim encrypted As Byte() = csp.SignHash(hash, "SHA256")
    
asked by anonymous 02.10.2015 / 21:23

3 answers

1

There are several possible causes; however the most common is when the issued certificate does not support the desired signature algorithm.

To verify, open the certificate and select Detalhes . The following must be present:

If necessary, re-issue the certificate with the SHA256 signing algorithm support.

    
05.10.2015 / 20:49
0

Try this.

Dim csp As SHA256 = DirectCast (Certificate.PrivateKey, SHA256CryptoServiceProvider)

I can not test now, but I think it's conflicting in the application RSA x SHA256.

    
05.10.2015 / 20:11
0

Look at this simple example, by running the SHA256 directly in a text, debug the methods to add the certificate, in this case, the right certificate id? to use as a keyword.

Private Function Encriptar(ByVal TextoEncriptar As String) As String
    Dim TextoEncriptado As String
    Dim TextoBytes() As Byte

    'Saber os Bytes do texto a encriptar
    TextoBytes = System.Text.Encoding.Unicode.GetBytes(TextoEncriptar)

    'Nova Instancia SHA256
    Dim HashSha As New SHA256Managed

    'Calcular hash do texto em bytes
    TextoBytes = HashSha.ComputeHash(TextoBytes)

    'Converter o array de bytes 
   TextoEncriptado  = Convert.ToBase64String(TextoBytes)


    Return TextoEncriptado 
  End Function
  

link

    
07.10.2015 / 21:20