2
I am signing the following string: 339575410000100000000000120150413NI0000000000000500000000002502917N207293716000260
Using the following code:
' Obtem o certificado
Dim CertificadoDig As X509Certificate2 = ObtemCertificado("")
' Converte os dados ASCII para Bytes
Dim data() As Byte = System.Text.Encoding.ASCII.GetBytes(String_AssADC)
Dim csp As RSACryptoServiceProvider = DirectCast(CertificadoDig.PrivateKey, RSACryptoServiceProvider)
'Gerando Hash(array de bytes) utilizando SHA1
Dim sha As New SHA1Managed()
Dim hash() As Byte = sha.ComputeHash(data)
'Assinando o HASH(array de bytes) utilizando RSA-SHA1
Dim encrypted As Byte() = csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"))
'Verifica se a Assinatura é Valida
Dim isValid As Boolean = csp.VerifyData(data, "SHA1", encrypted)
Return Convert.ToBase64String(encrypted)
I was wondering if when I saw Hash, did he sign? Because I saw that this can happen, and if this happens I will be signing twice and I believe that there must be the error, the Webservice of the Municipality of São Paulo, returns with the following message:
<?xml version="1.0" encoding="UTF-8" ?>
<RetornoEnvioRPS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe">
<Cabecalho Versao="1" xmlns="">
<Sucesso>false</Sucesso>
</Cabecalho>
<Erro xmlns="">
<Codigo>1057</Codigo>
<Descricao>Rejeição: Assinatura difere do calculado.</Descricao>
</Erro>
</RetornoEnvioRPS>