Assinar digitalmente um arquivo
Moderador: Moderadores
Assinar digitalmente um arquivo
Pessoal pra informação aki entrei em contato com o suporte e cancelaram o certifcado antigo pq não conseguia exportar em PFX e mandaram novamente pendindo pra fazer via FIREFOX o processo.. blz ai funcionou. ok...
Sun Tzu há mais de três mil anos cita nas epígrafes de seu livro “A Arte da Guerra“:
“Concentre-se nos pontos fortes, reconheça as fraquezas, agarre as oportunidades e proteja-se contra as ameaças”.
“Se não é vantajoso, nunca envie suas tropas; se não lhe rende ganhos, nunca utilize seus homens; se não é uma situação perigosa, nunca lute uma batalha precipitada”.
Até 2017 Desktop Console [ Legado ] Harbour | MinGW | DBF | CDX | FastReport | MySQL
Novos Projetos:
Desktop Visual Windev Desktop
Celular Android/iOS Windev Mobile
WEB Windev Web
Sejamos gratos a Deus.
“Concentre-se nos pontos fortes, reconheça as fraquezas, agarre as oportunidades e proteja-se contra as ameaças”.
“Se não é vantajoso, nunca envie suas tropas; se não lhe rende ganhos, nunca utilize seus homens; se não é uma situação perigosa, nunca lute uma batalha precipitada”.
Até 2017 Desktop Console [ Legado ] Harbour | MinGW | DBF | CDX | FastReport | MySQL
Novos Projetos:
Desktop Visual Windev Desktop
Celular Android/iOS Windev Mobile
WEB Windev Web
Sejamos gratos a Deus.
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
Assinar digitalmente um arquivo
Só pra atualizar a informação:
Acabo de comprar o certificado novamente da ksoftware, desta vez pra 4 anos.
O processo desta vez foi mais facilitado, porque a confirmação por telefone tinha opção em português.
Fiz o pedido ontem a noite, e acabo de gerar o novo certificado, já instalado e em funcionamento.
US$67,00 pra cada ano, total aproximado R$1.095,00.
Certificado emitido pela COMODO, o mesmo se fosse comprado no Brasil.
Acabo de comprar o certificado novamente da ksoftware, desta vez pra 4 anos.
O processo desta vez foi mais facilitado, porque a confirmação por telefone tinha opção em português.
Fiz o pedido ontem a noite, e acabo de gerar o novo certificado, já instalado e em funcionamento.
US$67,00 pra cada ano, total aproximado R$1.095,00.
Certificado emitido pela COMODO, o mesmo se fosse comprado no Brasil.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
-
pauloa1
- Usuário Nível 3

- Mensagens: 227
- Registrado em: 25 Jun 2008 14:57
- Localização: Augusto Pestana-RS
Assinar digitalmente um arquivo
Hazael!
Não da pra compartilhar, pois aparece o dados da empresa que gerou o certificado, na aba Assinaturas digitais.
Paulo
Não da pra compartilhar, pois aparece o dados da empresa que gerou o certificado, na aba Assinaturas digitais.
Paulo
- rochinha
- Administrador

- Mensagens: 4664
- Registrado em: 18 Ago 2003 20:43
- Localização: São Paulo - Brasil
- Contato:
Assinar digitalmente um arquivo
Amiguinhos,
Estou subindo dois utilitários para manuseio de certificados que espero auxiliem os amigos na geração, instalação e etc de certificados.
Renomear para makecert.exe
Uso: MakeCert [ basic|extended options] [outputCertificateFile]
Basic Options
-sk <keyName> Subject's key container name; To be created if not present
-ss <store> Subject's certificate store name that stores the output
certificate
-sr <location> Subject's certificate store location.
<CurrentUser|LocalMachine>. Default to 'CurrentUser'
-# <number> Serial Number from 1 to 2^31-1. Default to be unique
-$ <authority> The signing authority of the certificate
<individual|commercial>
-n <X509name> Certificate subject X500 name (eg: CN=Fred Dews)
-? Return a list of basic options
-! Return a list of extended options
Renomear para winhttpcertcfg.exe
Uso: winhttpcertcfg [-i PFXFile | -g | -r | -l]
[-a Account] [-c CertStore]
[-s SubjectStr] [-p PFXPassword]
The following table lists parameters for the configuration tool.
Parameter Description
-? Displays syntax data.
-i Specifies that the certificate is to be imported from a Personal Information Exchange (PFX) file. This parameter must be followed by the name of the file. When this parameter is specified, "-a" and "-c" must also be specified.
-g Specifies that access is granted to a private key. When this parameter is specified, "-a", "-c", and "-s" must also be specified.
-r Specifies that access is removed for a private key. When this parameter is specified, "-a", "-c", and "-s" must also be specified.
-l Specifies that accounts with access to a private key are listed. When this parameter is specified, "-c" and "-s" must also be specified.
-a Specifies the user account on the machine being configured. This could be a local machine or domain account, such as "IWAM_TESTMACHINE", "TESTUSER", or "TESTDOMAIN\DOMAINUSER".
-c Specifies the location and name of the certificate store. Use "LOCAL_MACHINE" or "CURRENT_USER" to designate which registry branch to use for the location. The certificate store can be any installed on the machine. Typical name examples are "MY", "Root", and "TrustedPeople". The location and name of the certificate store are separated with a backward slash, for example, "LOCAL_MACHINE\Root".
[!Note]
Although the "CURRENT_USER" branch of the registry can be specified with this parameter, extending access to private keys is primarily intended for certificates installed in a local computer certificate store that can be accessed by multiple users.
-s Specifies a case-insensitive search string for finding the first enumerated certificate with a subject name that contains this substring.
-p Specifies a password that is used to import the certificate and the private key. This is only used with the import option.
Estou subindo dois utilitários para manuseio de certificados que espero auxiliem os amigos na geração, instalação e etc de certificados.
Renomear para makecert.exe
Uso: MakeCert [ basic|extended options] [outputCertificateFile]
Basic Options
-sk <keyName> Subject's key container name; To be created if not present
-ss <store> Subject's certificate store name that stores the output
certificate
-sr <location> Subject's certificate store location.
<CurrentUser|LocalMachine>. Default to 'CurrentUser'
-# <number> Serial Number from 1 to 2^31-1. Default to be unique
-$ <authority> The signing authority of the certificate
<individual|commercial>
-n <X509name> Certificate subject X500 name (eg: CN=Fred Dews)
-? Return a list of basic options
-! Return a list of extended options
Renomear para winhttpcertcfg.exe
Uso: winhttpcertcfg [-i PFXFile | -g | -r | -l]
[-a Account] [-c CertStore]
[-s SubjectStr] [-p PFXPassword]
The following table lists parameters for the configuration tool.
Parameter Description
-? Displays syntax data.
-i Specifies that the certificate is to be imported from a Personal Information Exchange (PFX) file. This parameter must be followed by the name of the file. When this parameter is specified, "-a" and "-c" must also be specified.
-g Specifies that access is granted to a private key. When this parameter is specified, "-a", "-c", and "-s" must also be specified.
-r Specifies that access is removed for a private key. When this parameter is specified, "-a", "-c", and "-s" must also be specified.
-l Specifies that accounts with access to a private key are listed. When this parameter is specified, "-c" and "-s" must also be specified.
-a Specifies the user account on the machine being configured. This could be a local machine or domain account, such as "IWAM_TESTMACHINE", "TESTUSER", or "TESTDOMAIN\DOMAINUSER".
-c Specifies the location and name of the certificate store. Use "LOCAL_MACHINE" or "CURRENT_USER" to designate which registry branch to use for the location. The certificate store can be any installed on the machine. Typical name examples are "MY", "Root", and "TrustedPeople". The location and name of the certificate store are separated with a backward slash, for example, "LOCAL_MACHINE\Root".
[!Note]
Although the "CURRENT_USER" branch of the registry can be specified with this parameter, extending access to private keys is primarily intended for certificates installed in a local computer certificate store that can be accessed by multiple users.
-s Specifies a case-insensitive search string for finding the first enumerated certificate with a subject name that contains this substring.
-p Specifies a password that is used to import the certificate and the private key. This is only used with the import option.
OPS! LINK QUEBRADO? Veja ESTE TOPICO antes e caso não encontre ENVIE seu email com link do tópico para [url=mailto://fivolution@hotmail.com]fivolution@hotmail.com[/url]. Agradecido.
@braços : ? )
A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
@braços : ? )
A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
- rochinha
- Administrador

- Mensagens: 4664
- Registrado em: 18 Ago 2003 20:43
- Localização: São Paulo - Brasil
- Contato:
Assinar digitalmente um arquivo
Amiguinhos,
Consegui assinar com este código:
Vale lembrar que criei este certificado em minha maquina seguindo algum tutorial da internet.
Algumas dicas importantes:
Fonte:http://www.sslshopper.com/article-most-common-openssl-commands.html
Comandos Gerais
---------------------
1- Gerar uma chave privada e requisição de assinatura de certificado (CSR)
# openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
2- Gerar um certificado auto-assinado
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt
3- Gerar uma requisição de assinatura de certificado (CSR) para uma chave privada existente
#openssl req -out CSR.csr -key privateKey.key -new
4- Gerar uma requisição de assinatura de certificado baseado em um certificado existente
# openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key
5- Remover senha da chave privada
# openssl rsa -in privateKey.pem -out newPrivate.pem
Comandos para checagem usando openSSL
----------------------------------------------------
1- Checar a requisição de assinatura de certificado.
#openssl req -text -noout -verify -in CSR.csr
2- Checar a chave privada.
#openssl rsa -in privateKey.key -check
3 - Checar o certificado.
#openssl x509 -in certificate.crt -text -noout
4- Checar arquivo pkcs#12 (.pfx ou .p12)
#openssl pkcs12 -info -in keyStore.p12
Debugar utilizando OpenSSL
-----------------------------------
1- Verifique o hash MD5 da chave pública se é igual ao do CSR ou da chave privada
#openssl x509 -noout -modulus -in certificate.crt | openssl md5
#openssl rsa -noout -modulus -in privateKey.key | openssl md5
#openssl req -noout -modulus -in CSR.csr | openssl md5
2- Verifique a conexão SSL . Todos os certificados (incluindo os intermediários) devem ser exibidos
#openssl s_client -connect www.paypal.com:443
Conversões de formatos utilizando OpenSSL
-----------------------------------------------------
1- Converter arquivo DER (.crt .cer .der) para PEM
#openssl x509 -inform der -in certificate.cer -out certificate.pem
2- Converter de PEM para DER
# openssl x509 -outform der -in certificate.pem -out certificate.der
3- Converter de arquivo PKCS#12 (.pfx .p12) contendo chave privada e certificados para PEM
#openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes
You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
4-Converter um certificado PEM com chave privada para PKCS#12 (.pfx .p12)
# openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
Para que não quebre a cabeça procurando onde postaram como criar, ai vai:
Para entender o makecert visite https://docs.microsoft.com/pt-br/azure/vpn-gateway/vpn-gateway-certificates-point-to-site-makecert
Baixe aqui uma versão mais atual caso ainda não a tenha na maquina. Geralmente fica na pasta C:\Program Files\Microsoft SDKs\Windows\v7.1 para Windows Seven.
O winhttpcertcfg.exe serve para instalar o certificado. Para entender como usá-lo visite https://docs.microsoft.com/en-us/windows/desktop/winhttp/winhttpcertcfg-exe--a-certificate-configuration-tool
Caso as ferramentas acima estejam instaladas em sua maquina, execute os passos a seguir:
Vai pedir senha em vários passos, coloque a mesma em todas as perguntas até que estejam gerados os arquivos.
No exemplo acima o .PFX ficou sem senha e na hora de instalar ao pedir senha deixe em branco e marque o campo ...Exportável.. e confirme.
Consegui assinar com este código:
Código: Selecionar todos
// #include "fivewin.ch"
// Code Sign
// https://github.com/JoseQuintas/sefazclass/blob/master/drafts/CodeSign.prg
#define URL "http://timestamp.verisign.com/scripts/timstamp.dll"
PROCEDURE Main
LOCAL oSignedCode, oSigner, oElement
LOCAL lInterage := .T.
Pega_Certificado(lInterage)
oSignedCode := win_OleCreateObject( "CAPICOM.SignedCode" )
oSigner := win_OleCreateObject( "CAPICOM.Signer" )
oSignedCode:FileName := "c:\sistema\executavel.exe"
oSignedCode:Description := "José C. Rocha"
oSignedCode:DescriptionURL := "www.5volution.com.br"
?"1", oSignedCode:Sign( oSigner, .t., 0 )
?"2", oSignedCode:TimeStamp( URL )
?"3", oSignedCode:Verify()
FOR EACH oElement IN oSignedCode:Certificates
? oElement:SubjectName
NEXT
RETURN
function win_OleCreateObject( _qual_ )
return TOleAuto():New( _qual_ )
********************************
Function Pega_Certificado(lInterage)
***************************************************************
* Retorna um Vetor com o numero de serie na primeira possição *
* e o vencimento do certificado na segunda possição *
* Leonardo Machado - 03/05/2010 *
***************************************************************
Local oCerts1, oCerts2, oCerts3, oStore, oCertificates, aVETOR:={}
default lInterage := .f.
oCertificates := win_OleCreateObject( "CAPICOM.Certificates" )
oStore := win_OleCreateObject( "CAPICOM.Store" )
// Encripta Uma string
cEncryptedData:= MemoRead( "Encrypted.txt" )
oEncryptedData:= TOleAuto():New( "CAPICOM.EncryptedData" )
oEncryptedData:Content := cEncryptedData
oEncryptedData:SetSecret(cEncryptedData,0)
? procline(), cEncryptedData, oEncryptedData:Encrypt
cString := oEncryptedData:Encrypt
// Desencripta Uma string
oEncryptedData:= TOleAuto():New( "CAPICOM.EncryptedData" )
oEncryptedData:SetSecret(cEncryptedData)
oEncryptedData:Decrypt(cString)
? procline(),oEncryptedData:Content
oStore:open(2,'My',2)
oCerts1:=oStore:Certificates()
oCerts2:=oCerts1:Select("Selecione o certificado para uso da Nfe","Selecione o certificado",lInterage)
IF oCerts2:Count() > 0
oCerts3 := oCerts2:Item(1)
AADD(aVETOR,{oCerts3:SerialNumber,oCerts3:ValidToDate})
ENDIF
Return(aVETOR)
Algumas dicas importantes:
Fonte:http://www.sslshopper.com/article-most-common-openssl-commands.html
Comandos Gerais
---------------------
1- Gerar uma chave privada e requisição de assinatura de certificado (CSR)
# openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
2- Gerar um certificado auto-assinado
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt
3- Gerar uma requisição de assinatura de certificado (CSR) para uma chave privada existente
#openssl req -out CSR.csr -key privateKey.key -new
4- Gerar uma requisição de assinatura de certificado baseado em um certificado existente
# openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key
5- Remover senha da chave privada
# openssl rsa -in privateKey.pem -out newPrivate.pem
Comandos para checagem usando openSSL
----------------------------------------------------
1- Checar a requisição de assinatura de certificado.
#openssl req -text -noout -verify -in CSR.csr
2- Checar a chave privada.
#openssl rsa -in privateKey.key -check
3 - Checar o certificado.
#openssl x509 -in certificate.crt -text -noout
4- Checar arquivo pkcs#12 (.pfx ou .p12)
#openssl pkcs12 -info -in keyStore.p12
Debugar utilizando OpenSSL
-----------------------------------
1- Verifique o hash MD5 da chave pública se é igual ao do CSR ou da chave privada
#openssl x509 -noout -modulus -in certificate.crt | openssl md5
#openssl rsa -noout -modulus -in privateKey.key | openssl md5
#openssl req -noout -modulus -in CSR.csr | openssl md5
2- Verifique a conexão SSL . Todos os certificados (incluindo os intermediários) devem ser exibidos
#openssl s_client -connect www.paypal.com:443
Conversões de formatos utilizando OpenSSL
-----------------------------------------------------
1- Converter arquivo DER (.crt .cer .der) para PEM
#openssl x509 -inform der -in certificate.cer -out certificate.pem
2- Converter de PEM para DER
# openssl x509 -outform der -in certificate.pem -out certificate.der
3- Converter de arquivo PKCS#12 (.pfx .p12) contendo chave privada e certificados para PEM
#openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes
You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
4-Converter um certificado PEM com chave privada para PKCS#12 (.pfx .p12)
# openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
Para que não quebre a cabeça procurando onde postaram como criar, ai vai:
Código: Selecionar todos
rem baixar openssl light e executar como administrador
c:\openssl\bin\openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
c:\openssl\bin\openssl pkcs12 -export -out mycert.pfx -in mycert.pem -name "onome"
Baixe aqui uma versão mais atual caso ainda não a tenha na maquina. Geralmente fica na pasta C:\Program Files\Microsoft SDKs\Windows\v7.1 para Windows Seven.
O winhttpcertcfg.exe serve para instalar o certificado. Para entender como usá-lo visite https://docs.microsoft.com/en-us/windows/desktop/winhttp/winhttpcertcfg-exe--a-certificate-configuration-tool
Caso as ferramentas acima estejam instaladas em sua maquina, execute os passos a seguir:
Código: Selecionar todos
@del hazael.pvk
@del hazael.cer
@del hazael.pfx
@del ServerCert.pvk
@del ServerCert.cer
@makecert -sky signature -r -pe -n "CN=hazael" -a sha1 -cy authority -sv hazael.pvk hazael.cer
@certutil -addstore Root hazael.cer
@makecert -pe -n "CN=ServerCert" -a sha1 -sky exchange -ic hazael.cer -iv hazael.pvk -sv ServerCert.pvk ServerCert.cer
@pvk2pfx -pvk ServerCert.pvk -spc ServerCert.cer -pfx hazael.pfx
@dir *.cer *.pvk *.pfx
No exemplo acima o .PFX ficou sem senha e na hora de instalar ao pedir senha deixe em branco e marque o campo ...Exportável.. e confirme.
OPS! LINK QUEBRADO? Veja ESTE TOPICO antes e caso não encontre ENVIE seu email com link do tópico para [url=mailto://fivolution@hotmail.com]fivolution@hotmail.com[/url]. Agradecido.
@braços : ? )
A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
@braços : ? )
A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
- rochinha
- Administrador

- Mensagens: 4664
- Registrado em: 18 Ago 2003 20:43
- Localização: São Paulo - Brasil
- Contato:
Assinar digitalmente um arquivo
OPS! LINK QUEBRADO? Veja ESTE TOPICO antes e caso não encontre ENVIE seu email com link do tópico para [url=mailto://fivolution@hotmail.com]fivolution@hotmail.com[/url]. Agradecido.
@braços : ? )
A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
@braços : ? )
A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
