Esempio n. 1
0
        static byte[] Sha384(byte[] dat)
        {
            Sha384Digest digester = new Sha384Digest();

            byte[] retValue = new byte[digester.GetDigestSize()];
            digester.BlockUpdate(dat, 0, dat.Length);
            digester.DoFinal(retValue, 0);
            return(retValue);
        }
Esempio n. 2
0
        public static byte[] ComputeSha384(byte[] data)
        {
            IDigest digest = new Sha384Digest();

            byte[] buffer = new byte[digest.GetDigestSize()];
            digest.BlockUpdate(data, 0, data.Length);
            digest.DoFinal(buffer, 0);
            return(buffer);
        }
Esempio n. 3
0
        public static byte[] Hash384(byte[] value)
        {
            var digest = new Sha384Digest();
            var output = new byte[digest.GetDigestSize()];

            digest.BlockUpdate(value, 0, value.Length);
            digest.DoFinal(output, 0);

            return(output);
        }
Esempio n. 4
0
        public static byte[] Hash384(byte[] message)
        {
            var digest = new Sha384Digest();
            var output = new byte[digest.GetDigestSize()];

            byte[] msg = message ?? new byte[0];
            digest.BlockUpdate(msg, 0, msg.Length);
            digest.DoFinal(output, 0);

            return(output);
        }
Esempio n. 5
0
        public static byte[] Digest(byte[] data, String algo)
        {
            if (algo == null)
            {
                throw new ArgumentNullException("El algoritmo de huella digital no puede ser nulo");
            }
            if (data == null)
            {
                throw new ArgumentNullException("Los datos no pueden ser nulos");
            }

            switch (algo)
            {
            /**
             * ALGORITMOS DE HASING
             */
            case AOSignConstants.SIGN_ALGORITHM_SHA1:
            {
                Sha1Digest dig = new Sha1Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            case AOSignConstants.SIGN_ALGORITHM_SHA256:
            {
                Sha256Digest dig = new Sha256Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            case AOSignConstants.SIGN_ALGORITHM_SHA384:
            {
                Sha384Digest dig = new Sha384Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            case AOSignConstants.SIGN_ALGORITHM_SHA512:
            {
                Sha512Digest dig = new Sha512Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            case AOSignConstants.SIGN_ALGORITHM_RIPEMD160:
            {
                RipeMD160Digest dig = new RipeMD160Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            case AOSignConstants.SIGN_ALGORITHM_MD5:
            {
                MD5Digest dig = new MD5Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            case AOSignConstants.SIGN_ALGORITHM_MD2:
            {
                MD2Digest dig = new MD2Digest();
                dig.BlockUpdate(data, 0, data.Length);
                byte[] result = new byte[dig.GetDigestSize()];
                dig.DoFinal(result, 0);
                return(result);
            }

            default:
                // You can use the default case.
                throw new ArgumentNullException("El algoritmo no es reconocido");
            }


            throw new ArgumentNullException("Algoritmo de hash no soportado: " + algo);
        }
Esempio n. 6
0
        public ITestResult Perform()
        {
            IDigest digest = new Sha384Digest();

            byte[] resBuf = new byte[digest.GetDigestSize()];
            string resStr;

            //
            // test 1
            //
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec1.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA-384 failing standard vector test 1"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec1
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            //
            // test 2
            //
            byte[] bytes = Hex.Decode(testVec2);
            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec2.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA-384 failing standard vector test 2"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec2
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            //
            // test 3
            //
            bytes = Hex.Decode(testVec3);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec3.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA-384 failing standard vector test 3"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec3
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            //
            // test 4
            //
            bytes = Hex.Decode(testVec4);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA-384 failing standard vector test 4"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec4
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            //
            // test 5
            //
            bytes = Hex.Decode(testVec4);

            digest.BlockUpdate(bytes, 0, bytes.Length / 2);

            // clone the IDigest
            IDigest d = new Sha384Digest((Sha384Digest)digest);

            digest.BlockUpdate(bytes, bytes.Length / 2, bytes.Length - bytes.Length / 2);
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA384 failing standard vector test 5"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec4
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            d.BlockUpdate(bytes, bytes.Length / 2, bytes.Length - bytes.Length / 2);
            d.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA384 failing standard vector test 5"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec4
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            // test 6
            bytes = Hex.Decode(testVec5);
            for (int i = 0; i < 100000; i++)
            {
                digest.BlockUpdate(bytes, 0, bytes.Length);
            }
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec5.Equals(resStr))
            {
                return(new SimpleTestResult(false,
                                            "SHA-384 failing standard vector test 5"
                                            + SimpleTest.NewLine
                                            + "    expected: " + resVec5
                                            + SimpleTest.NewLine
                                            + "    got     : " + resStr));
            }

            return(new SimpleTestResult(true, Name + ": Okay"));
        }