/// <summary> /// Supply a mnemonic sentence with any words of your choosing not restricted to wordlists and be given seed bytes in return /// </summary> /// <param name="mnemonicSentence"> /// The mnemonic sentence we will use to derive seed bytes, Please ensure NFKD Normalized /// </param> /// <param name="passphrase"> /// Optional passphrase to protect the seed bytes, Please ensure NFKD Normalized, defaults to empty string /// </param> /// <returns> /// Seed bytes that can be used to create a root in BIP32 /// </returns> public static byte[] GetSeedBytes(string mnemonicSentence, string passphrase = CEmptyString) { mnemonicSentence = mnemonicSentence.Normalize(NormalizationForm.FormKD); var salt = Encoding.UTF8.GetBytes(CSaltHeader).Concat(Encoding.UTF8.GetBytes(passphrase.Normalize(NormalizationForm.FormKD))).ToArray(); return(Bip39Kdf.Pbkdf2(Encoding.UTF8.GetBytes(mnemonicSentence), salt)); }
/// <summary> /// A static publicly exposed version of GetDerivedKeyBytes_PBKDF2_HMACSHA512 which matches the exact specification in Rfc2898 PBKDF2 using HMACSHA512 /// </summary> /// <param name="P"> /// Password passed as a Byte Array /// </param> /// <param name="S"> /// Salt passed as a Byte Array /// </param> /// <param name="c"> /// Iterations to perform the underlying PRF over /// </param> /// <param name="dkLen"> /// Length of Bytes to return, an AES 256 key wold require 32 Bytes /// </param> /// <returns> /// Derived Key in Byte Array form ready for use by chosen encryption function /// </returns> public static byte[] Pbkdf2(byte[] P, byte[] S, int c = CMinIterations, int dkLen = hLen) { Bip39Kdf rfcObj = new Bip39Kdf(P, S, c); return(rfcObj.GetDerivedKeyBytes_PBKDF2_HMACSHA512(dkLen)); }