/// <summary>Sets root key.</summary> /// <param name="value">The value to set.</param> private void SetRootKey(RootKeyType value) { if (this.rootKeys != null && this.rootKeys.Text != null) { rootKeys.Items.IndexOf(value); } }
public static ExtKey GetExtRoot(string input, string passPhrase = "", RootKeyType keyType = RootKeyType.Legacy) { var mnemo = new NBitcoin.Mnemonic(NormalizeSeedPhrase(input)); byte[] pbkf_hmacked; { // Generate a salt var saltBytes = Encoding.UTF8.GetBytes("electrum" + passPhrase); // Generate the hash // TODO: .Net Standard 2.0 var pbkdf2 = new Rfc2898DeriveBytes( mnemo.ToString(), saltBytes, 2048, HashAlgorithmName.SHA512 ); var keyByte = Encoding.UTF8.GetBytes("Bitcoin seed"); var hmacsha512 = new HMACSHA512(keyByte); pbkf_hmacked = hmacsha512.ComputeHash(pbkdf2.GetBytes(64)); } var fullKey = new byte[4 + 1 + 4 + 4 + 32 + 1 + 32]; Array.Copy(new byte[] { 0x04, 0x88, 0xAD, 0xE4, }, fullKey, 4); Array.Copy(pbkf_hmacked, 32, fullKey, 4 + 1 + 4 + 4, 32); Array.Copy(pbkf_hmacked, 0, fullKey, 4 + 1 + 4 + 4 + 32 + 1, 32); // var xpriv = Base58CheckEncoding.Encode(fullKey); var chainCode = new byte[32]; Array.Copy(fullKey, 4 + 1 + 4 + 4, chainCode, 0, 32); var keyHex = new byte[32]; Array.Copy(fullKey, 4 + 1 + 4 + 4 + 32 + 1, keyHex, 0, 32); var HDRoot = new ExtKey(new Key(keyHex), chainCode); return(HDRoot); }
/// <summary>Initializes a new instance of the <see cref="QueryItem"/> class. Create a new query item object.</summary> /// <param name="rootKey">The root key.</param> /// <param name="keyName">The registry key name.</param> /// <value>A new query item.</value> public QueryItem(RootKeyType rootKey, string keyName) { Contract.Requires<ArgumentNullException>(keyName != null, "keyName cannot be null"); this.RootKey = rootKey; this.KeyName = keyName; }
/// <summary>Create a Registry key.</summary> /// <param name="rootKey">The root key to use.</param> /// <param name="keyName">A valid registry key string.</param> /// <returns>The opened key.</returns> public static RegistryKey New(RootKeyType rootKey, string keyName) { Contract.Requires<ArgumentNullException>(keyName != null, "keyName cannot be null"); if (!string.IsNullOrEmpty(keyName)) { switch (rootKey) { case RootKeyType.HKLM: return Registry.LocalMachine.OpenSubKey(keyName); case RootKeyType.HKCC: return Registry.CurrentConfig.OpenSubKey(keyName); case RootKeyType.HKCR: return Registry.ClassesRoot.OpenSubKey(keyName); case RootKeyType.HKU: return Registry.Users.OpenSubKey(keyName); case RootKeyType.HKCU: return Registry.CurrentUser.OpenSubKey(keyName); case RootKeyType.HKPD: return Registry.PerformanceData.OpenSubKey(keyName); } } else { switch (rootKey) { case RootKeyType.HKLM: return Registry.LocalMachine; case RootKeyType.HKCC: return Registry.CurrentConfig; case RootKeyType.HKCR: return Registry.ClassesRoot; case RootKeyType.HKU: return Registry.Users; case RootKeyType.HKCU: return Registry.CurrentUser; case RootKeyType.HKPD: return Registry.PerformanceData; } } throw new ArgumentException("Unknown RootKeyType."); }
/// <summary>Create a Registry key.</summary> /// <param name="rootKey">The root key to use.</param> /// <returns>The opened key.</returns> public static RegistryKey New(RootKeyType rootKey) { return New(rootKey, string.Empty); }
/// <summary>Set query item.</summary> /// <param name="item">The query item.</param> /// <exception cref="ArgumentNullException">item is null</exception> /// <exception cref="ArgumentNullException">item.KeyName is null</exception> private void SetItem(QueryItem item) { Contract.Requires<ArgumentNullException>(item != null, "item cannot be null"); Contract.Requires<ArgumentNullException>(item.KeyName != null, "item.KeyName cannot be null"); if (item != null && item.KeyName != null) { this.RootKey = item.RootKey; this.KeyName = item.KeyName; } }