Ejemplo n.º 1
0
        private Boolean GenerarSelloSHA256(String CadenaOriginal, Certificado cert, out String Resultado, out List <String> ErrorSellado)
        {
            Boolean Devolver = false;

            Resultado = String.Empty;
            String SelloDigital  = String.Empty;
            String ErrorSellador = String.Empty;

            ErrorSellado = new List <string>();
            System.Security.Cryptography.SHA256CryptoServiceProvider EncriptaSHA256 = new System.Security.Cryptography.SHA256CryptoServiceProvider();
            Byte[] CadenaOriginalEnBytes = EncriptaSHA256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(CadenaOriginal));

            System.Security.Cryptography.RSACryptoServiceProvider RSA = null;
            byte[] keyblob = cert.bKey;
            if (keyblob != null)
            {
                if (SSLKey.opensslkey.DecodeEncryptedPrivateKeyInfo(keyblob, cert.ContrasenaSegura, out RSA, out ErrorSellador))
                {
                    //RSA.FromXmlString(LLavePrivada);
                    System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(RSA);
                    RSAFormatter.SetHashAlgorithm("SHA256");
                    CadenaOriginalEnBytes = RSAFormatter.CreateSignature(CadenaOriginalEnBytes);
                    SelloDigital          = Convert.ToBase64String(CadenaOriginalEnBytes);
                    Resultado             = SelloDigital;
                    Devolver = true;
                }
                else
                {
                    ErrorSellado.Add(ErrorSellador);
                }
            }

            return(Devolver);
        }
Ejemplo n.º 2
0
 public Sellador(String ArchivoKey, String ArchivoCert, String Contraseña, bool sha256 = true)
 {
     try
     {
         keyFile  = ArchivoKey;
         certFile = ArchivoCert;
         Password = Contraseña;
         if (!String.IsNullOrEmpty(certFile))
         {
             if (System.IO.File.Exists(certFile))
             {
                 Cert = new Certificado(certFile);
             }
             else
             {
                 throw new Exception("No se puede encontrar el certificado", new Exception(certFile));
             }
         }
         else
         {
             throw new Exception("Error debe especificarse el certificado");
         }
     }
     catch (Exception e)
     {
         throw new Exception("Error en constructor sellador", new Exception(e.Message));
     }
 }
Ejemplo n.º 3
0
 public Sellador(Certificado cert)
 {
     Cert = cert;
 }