Пример #1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Hash != null)
         {
             hashCode = hashCode * 59 + Hash.GetHashCode();
         }
         if (HashAlgo != null)
         {
             hashCode = hashCode * 59 + HashAlgo.GetHashCode();
         }
         if (Nonce != null)
         {
             hashCode = hashCode * 59 + Nonce.GetHashCode();
         }
         if (ClientData != null)
         {
             hashCode = hashCode * 59 + ClientData.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #2
0
        public void DoHash(PGPReader Reader, HashAlgorithm[] HashAlgorithms)
        {
            long TotalBytes     = Reader.BytesRemaining;
            long RemainingBytes = TotalBytes;

            byte[] Buffer      = new byte[4096];
            long   CurrentTick = DateTime.Now.Ticks;

            while (RemainingBytes > 0)
            {
                int BytesToRead = (int)RemainingBytes;
                if (BytesToRead > Buffer.Length)
                {
                    BytesToRead = Buffer.Length;
                }

                int BytesRead = Reader.Read(Buffer, 0, BytesToRead);

                foreach (var HashAlgo in HashAlgorithms)
                {
                    HashAlgo.TransformBlock(Buffer, 0, BytesRead, Buffer, 0);
                }

                if (CurrentTick + 10000000 < DateTime.Now.Ticks)
                {
                    CurrentTick = DateTime.Now.Ticks;
                    ProgressUpdate?.Invoke("Computing Hash...", (int)(100 * (TotalBytes - RemainingBytes) / TotalBytes));
                }
                RemainingBytes -= BytesRead;
            }
        }
Пример #3
0
        /// <summary>
        /// Returns true if InputSignaturesTimestamp instances are equal
        /// </summary>
        /// <param name="other">Instance of InputSignaturesTimestamp to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(InputSignaturesTimestamp other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Hash == other.Hash ||
                     Hash != null &&
                     Hash.Equals(other.Hash)
                     ) &&
                 (
                     HashAlgo == other.HashAlgo ||
                     HashAlgo != null &&
                     HashAlgo.Equals(other.HashAlgo)
                 ) &&
                 (
                     Nonce == other.Nonce ||
                     Nonce != null &&
                     Nonce.Equals(other.Nonce)
                 ) &&
                 (
                     ClientData == other.ClientData ||
                     ClientData != null &&
                     ClientData.Equals(other.ClientData)
                 ));
        }
Пример #4
0
        public static string ComputeHash(string text, string salt, HashAlgo hashType)
        {
            byte[] bytes = ASCIIEncoding.UTF8.GetBytes(text + salt);
            byte[] hash  = null;

            switch (hashType)
            {
            case HashAlgo.SHA256:
                SHA256Managed sha256 = new SHA256Managed();
                hash = sha256.ComputeHash(bytes);
                sha256.Dispose();
                break;

            case HashAlgo.SHA384:
                SHA384Managed sha384 = new SHA384Managed();
                hash = sha384.ComputeHash(bytes);
                sha384.Dispose();
                break;

            case HashAlgo.SHA512:
                SHA512Managed sha512 = new SHA512Managed();
                hash = sha512.ComputeHash(bytes);
                sha512.Dispose();
                break;
            }

            return(Convert.ToBase64String(hash));
        }
Пример #5
0
        // IBinarySerialize
        public void Write(BinaryWriter w) //(1)
        {
            var sb = new StringBuilder();

            foreach (var datapt in _context.Keys)
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "'{0}''{1}'", datapt, _context[datapt]);
            }

            var hashAlgo = new HashAlgo <SHA1CryptoServiceProvider>();

            string output = hashAlgo.ToBase64String(sb.ToString()).Replace('/', '_').Replace('+', '-');

            w.Write(output);
        }
Пример #6
0
        /// <summary>
        /// Returns true if InputSignaturesSignhash instances are equal
        /// </summary>
        /// <param name="other">Instance of InputSignaturesSignhash to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(InputSignaturesSignhash other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     CredentialID == other.CredentialID ||
                     CredentialID != null &&
                     CredentialID.Equals(other.CredentialID)
                     ) &&
                 (
                     SAD == other.SAD ||
                     SAD != null &&
                     SAD.Equals(other.SAD)
                 ) &&
                 (
                     Hash == other.Hash ||
                     Hash != null &&
                     Hash.Equals(other.Hash)
                 ) &&
                 (
                     HashAlgo == other.HashAlgo ||
                     HashAlgo != null &&
                     HashAlgo.Equals(other.HashAlgo)
                 ) &&
                 (
                     SignAlgo == other.SignAlgo ||
                     SignAlgo != null &&
                     SignAlgo.Equals(other.SignAlgo)
                 ) &&
                 (
                     SignAlgoParams == other.SignAlgoParams ||
                     SignAlgoParams != null &&
                     SignAlgoParams.Equals(other.SignAlgoParams)
                 ) &&
                 (
                     ClientData == other.ClientData ||
                     ClientData != null &&
                     ClientData.Equals(other.ClientData)
                 ));
        }
Пример #7
0
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create vectors
            var signatureVector = SecretLockTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = SecretLockTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = SecretLockTransactionBuffer.CreateFeeVector(builder, Fee.ToUInt8Array());
            var deadlineVector  = SecretLockTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var mosaicId        = SecretLockTransactionBuffer.CreateMosaicIdVector(builder, Mosaic.MosaicId.Id.ToUInt8Array());
            var mosaicAmount    = SecretLockTransactionBuffer.CreateMosaicAmountVector(builder, Mosaic.Amount.ToUInt8Array());
            var duration        = SecretLockTransactionBuffer.CreateDurationVector(builder, Duration.ToUInt8Array());
            var secretVector    = SecretLockTransactionBuffer.CreateSecretVector(builder, Secret);

            var    recipientVector = SecretLockTransactionBuffer.CreateRecipientVector(builder, Recipient.Plain.FromBase32String());
            ushort version         = ushort.Parse(NetworkType.GetNetworkByte().ToString("X") + "0" + Version.ToString("X"), System.Globalization.NumberStyles.HexNumber);

            // add vectors
            SecretLockTransactionBuffer.StartSecretLockTransactionBuffer(builder);
            SecretLockTransactionBuffer.AddSize(builder, 234);
            SecretLockTransactionBuffer.AddSignature(builder, signatureVector);
            SecretLockTransactionBuffer.AddSigner(builder, signerVector);
            SecretLockTransactionBuffer.AddVersion(builder, version);
            SecretLockTransactionBuffer.AddType(builder, TransactionTypes.Types.SecretLock.GetValue());
            SecretLockTransactionBuffer.AddFee(builder, feeVector);
            SecretLockTransactionBuffer.AddDeadline(builder, deadlineVector);
            SecretLockTransactionBuffer.AddMosaicId(builder, mosaicId);
            SecretLockTransactionBuffer.AddMosaicAmount(builder, mosaicAmount);
            SecretLockTransactionBuffer.AddDuration(builder, duration);
            SecretLockTransactionBuffer.AddHashAlgorithm(builder, HashAlgo.GetHashTypeValue());
            SecretLockTransactionBuffer.AddSecret(builder, secretVector);
            SecretLockTransactionBuffer.AddRecipient(builder, recipientVector);

            // end build
            var codedTransfer = SecretLockTransactionBuffer.EndSecretLockTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            return(new SecretLockTransactionSchema().Serialize(builder.SizedByteArray()));
        }
Пример #8
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (CredentialID != null)
         {
             hashCode = hashCode * 59 + CredentialID.GetHashCode();
         }
         if (SAD != null)
         {
             hashCode = hashCode * 59 + SAD.GetHashCode();
         }
         if (Hash != null)
         {
             hashCode = hashCode * 59 + Hash.GetHashCode();
         }
         if (HashAlgo != null)
         {
             hashCode = hashCode * 59 + HashAlgo.GetHashCode();
         }
         if (SignAlgo != null)
         {
             hashCode = hashCode * 59 + SignAlgo.GetHashCode();
         }
         if (SignAlgoParams != null)
         {
             hashCode = hashCode * 59 + SignAlgoParams.GetHashCode();
         }
         if (ClientData != null)
         {
             hashCode = hashCode * 59 + ClientData.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #9
0
 public static bool Verify(string text, string salt, HashAlgo hashType, string saltedHash)
 {
     return(saltedHash == ComputeHash(text, salt, hashType));
 }
Пример #10
0
 private void Sha512Radio_CheckedChanged(object sender, EventArgs e)
 {
     selectedHash = HashAlgo.SHA512;
 }
Пример #11
0
 private void RipemdRadio_CheckedChanged(object sender, EventArgs e)
 {
     selectedHash = HashAlgo.RipeMd;
 }
Пример #12
0
 private void Md5Radio_CheckedChanged(object sender, EventArgs e)
 {
     selectedHash = HashAlgo.MD5;
 }
Пример #13
0
 private void Form1_Load(object sender, EventArgs e)
 {
     BgWorker.ProgressChanged += new ProgressChangedEventHandler(BgWorker_ProgressChanged);
     BgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BgWorker_RunWorkerCompleted);
     FileNameTextBox.DragEnter += new DragEventHandler(FileNameTextBox_DragEnter);       // Drag & Drop Effects
     FileNameTextBox.DragDrop += new DragEventHandler(FileNameTextBox_DragDrop);         // Catch Drop
     this.DragEnter += new DragEventHandler(FileNameTextBox_DragEnter);
     this.DragDrop += new DragEventHandler(FileNameTextBox_DragDrop);
     selectedHash = HashAlgo.CRC32;
 }
Пример #14
0
 private void CrcRadio_CheckedChanged(object sender, EventArgs e)
 {
     selectedHash = HashAlgo.CRC32;
 }