예제 #1
0
        public void Execute()
        {
            ProgressChanged(0, 1);

            System.Security.Cryptography.HMAC hmacAlgorithm;

            switch ((HMACSettings.HashFunction)settings.SelectedHashFunction)
            {
            case HMACSettings.HashFunction.MD5:
                hmacAlgorithm = new System.Security.Cryptography.HMACMD5();
                break;

            case HMACSettings.HashFunction.RIPEMD160:
                hmacAlgorithm = new System.Security.Cryptography.HMACRIPEMD160();
                break;

            case HMACSettings.HashFunction.SHA1:
                hmacAlgorithm = new System.Security.Cryptography.HMACSHA1();
                break;

            case HMACSettings.HashFunction.SHA256:
                hmacAlgorithm = new System.Security.Cryptography.HMACSHA256();
                break;

            case HMACSettings.HashFunction.SHA384:
                hmacAlgorithm = new System.Security.Cryptography.HMACSHA384();
                break;

            case HMACSettings.HashFunction.SHA512:
                hmacAlgorithm = new System.Security.Cryptography.HMACSHA512();
                break;

            default:
                GuiLogMessage("No hash algorithm for HMAC selected, using MD5.", NotificationLevel.Warning);
                hmacAlgorithm = new System.Security.Cryptography.HMACMD5();
                break;
            }

            hmacAlgorithm.Key = key;

            OutputData = (inputData != null) ? hmacAlgorithm.ComputeHash(inputData.CreateReader()) : hmacAlgorithm.ComputeHash(new byte[] {});

            GuiLogMessage(String.Format("HMAC computed. (using hash algorithm {0}: {1})", settings.SelectedHashFunction, hmacAlgorithm.GetType().Name), NotificationLevel.Info);

            ProgressChanged(1, 1);
        }