Ejemplo n.º 1
0
        public static string GenerarHash(AssemblyHashAlgorithm algoritmo, string cadena)
        {
            HashAlgorithm algoritmoHash = HashAlgorithm.Create(algoritmo.ToString());

            try
            {
                byte[] buffer = algoritmoHash.ComputeHash(UTF7Encoding.UTF7.GetBytes(cadena));
                return(BitConverter.ToString(buffer, 0).ToUpperInvariant().Replace("-", string.Empty));
            }
            finally
            {
                if (algoritmoHash != null)
                {
                    algoritmoHash.Clear();
                }
            }
        }
Ejemplo n.º 2
0
        private void inicializar(string palabraClave, string semilla, AssemblyHashAlgorithm algoritmoHash, int numeroIteraciones)
        {
            byte[] bufferSemilla = Encoding.UTF8.GetBytes(semilla);

            PasswordDeriveBytes password = new PasswordDeriveBytes(palabraClave, bufferSemilla)
            {
                HashName = algoritmoHash.ToString(), IterationCount = numeroIteraciones
            };

            byte[] bufferKey = password.GetBytes(32);
            byte[] bufferIV  = password.GetBytes(16);

            this.algoritmoEncripcion      = new RijndaelManaged();
            this.algoritmoEncripcion.Mode = CipherMode.CBC;
            this.algoritmoEncripcion.Key  = bufferKey;
            this.algoritmoEncripcion.IV   = bufferIV;
        }
Ejemplo n.º 3
0
        private byte[] ComputeSignature(AssemblyHashAlgorithm hashAlgorithm, byte[] hash)
        {
            // Translate strong name private key to RSA parameters.
            using var rsa = RSA.Create();
            var rsaParameters = PrivateKey.ToRsaParameters();

            rsa.ImportParameters(rsaParameters);

            // Compute the signature.
            var formatter = new RSAPKCS1SignatureFormatter(rsa);

            formatter.SetHashAlgorithm(hashAlgorithm.ToString().ToUpperInvariant());
            var signature = formatter.CreateSignature(hash);

            Array.Reverse(signature);

            return(signature);
        }