Possible SHA256 return 128bytes after signing?

2

I am using the following code to get my certificate and sign my CNPJs, however I am using the SHA256 algorithm, but it is returning 128bytes. Does anyone know what's wrong? Follow the Code:

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


            ' cert = certificado X509
            Dim sha As New SHA256Managed()
            Dim hash As Byte() = sha.ComputeHash(data)
            Dim encrypted As Byte() = csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA256"))



            Me.txtBox.Text = Convert.ToBase64String(encrypted)

The variable date is 28 bytes long.

The hash variable is 32 bytes long.

The encrypted variable has 128 bytes < - PROBLEM

In the end my txtBox.text gets only 172Bytes and should get 344bytes if the "encrypted" variable was receiving 256bytes

    
asked by anonymous 06.11.2014 / 12:21

2 answers

1

I'll just start a discussion of what may be happening ...

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

 //vou continuar o exemplo em c#(não entendo muito vb.net)

 byte[] signature = csp.SignData(data, "SHA256");
 bool isValid = csp.VerifyData(data, "SHA256", signature);//verifica se e valido

//Conversao para UTF8 caso for necessario ser lido...
string final = Encoding.UTF8.GetString(signature);

A link that can help you

You can use CryptoConfig.MapNameToOID ("SHA256") instead of "SHA256", but I do not know what difference it will cause.

    
06.11.2014 / 13:19
2

SHA-256 has 256 bits and not 256 bytes . I'm trying to understand how it got so great.

256 bits are 32 bytes . There is even a need for 64 bytes

06.11.2014 / 12:53