Esempio n. 1
0
        public string GetSeal(byte[] rgbHash, System.Security.Cryptography.RSACryptoServiceProvider privateKey)
        {
            System.Security.Cryptography.RSAPKCS1SignatureFormatter rsaPKCS1 = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(privateKey);
            rsaPKCS1.SetHashAlgorithm("SHA256");

            return(Convert.ToBase64String(rsaPKCS1.CreateSignature(rgbHash)));
        }
Esempio n. 2
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);
        }
        private static async System.Threading.Tasks.Task <ResultType> TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, string a_key, Fee.TaskW.CancelToken a_cancel)
                #endif
        {
            ResultType t_ret;

            {
                t_ret.binary      = null;
                t_ret.errorstring = null;
            }

            try{
                //ハッシュの計算。
                byte[] t_hash_binary = null;
                using (System.Security.Cryptography.SHA1Managed t_sha1 = new System.Security.Cryptography.SHA1Managed()){
                    t_hash_binary = t_sha1.ComputeHash(a_binary);
                }

                if (t_hash_binary == null)
                {
                    t_ret.binary      = null;
                    t_ret.errorstring = "Task_CreateSignaturePrivateKey : hash == null";
                }
                else
                {
                    using (System.Security.Cryptography.RSACryptoServiceProvider t_rsa = new System.Security.Cryptography.RSACryptoServiceProvider()){
                        t_rsa.FromXmlString(a_key);

                        //証明書作成。
                        System.Security.Cryptography.RSAPKCS1SignatureFormatter t_formatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(t_rsa);
                        t_formatter.SetHashAlgorithm("SHA1");
                        t_ret.binary = t_formatter.CreateSignature(t_hash_binary);
                    }
                }
            }catch (System.Exception t_exception) {
                t_ret.binary      = null;
                t_ret.errorstring = "Task_CreateSignaturePrivateKey : " + t_exception.Message;
            }

            if (a_cancel.IsCancellationRequested() == true)
            {
                t_ret.binary      = null;
                t_ret.errorstring = "Task_CreateSignaturePrivateKey : Cancel";

                a_cancel.ThrowIfCancellationRequested();
            }

            if (t_ret.binary == null)
            {
                if (t_ret.errorstring == null)
                {
                    t_ret.errorstring = "Task_CreateSignaturePrivateKey : null";
                }
            }

            return(t_ret);
        }
Esempio n. 4
0
 public string SignatureFormatter(string m_strHashbyteSignature)
 {
     byte[] rgbHash = System.Convert.FromBase64String(m_strHashbyteSignature);
     System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = new System.Security.Cryptography.RSACryptoServiceProvider();
     rSACryptoServiceProvider.FromXmlString(this.p_strKeyPrivate);
     System.Security.Cryptography.RSAPKCS1SignatureFormatter rSAPKCS1SignatureFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(rSACryptoServiceProvider);
     rSAPKCS1SignatureFormatter.SetHashAlgorithm("MD5");
     byte[] inArray = rSAPKCS1SignatureFormatter.CreateSignature(rgbHash);
     return(System.Convert.ToBase64String(inArray));
 }
Esempio n. 5
0
        public byte[] sign()
        {
            //    byte[] sig=signature.sign();
            //    return sig;
            cs.Close();
            System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider();
            RSA.ImportParameters(RSAKeyInfo);
            System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(RSA);
            RSAFormatter.SetHashAlgorithm("SHA1");

            byte[] sig = RSAFormatter.CreateSignature(sha1);
            return(sig);
        }
Esempio n. 6
0
        public static byte[] CreateDigitalSignature(byte[] bytes, string privateKey)
        {
            using (var sha = new System.Security.Cryptography.SHA256Managed())
            {
                var hashData = sha.ComputeHash(bytes);

                using (var rsa = new System.Security.Cryptography.RSACryptoServiceProvider())
                {
                    rsa.FromXmlString(privateKey);

                    var rsaFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(rsa);
                    rsaFormatter.SetHashAlgorithm("SHA256");

                    var signedValue = rsaFormatter.CreateSignature(hashData);
                    return(signedValue);
                }
            }
        }
        public byte[] sign()
        {
            //    byte[] sig=signature.sign();
            //    return sig;
            cs.Close();
            System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider();
            RSA.ImportParameters(RSAKeyInfo);
            System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(RSA);
            RSAFormatter.SetHashAlgorithm("SHA1");

            byte[] sig = RSAFormatter.CreateSignature( sha1 );
            return  sig;
        }