/// <summary> /// Convert recovery phrase to SSB.Keys /// </summary> /// <param name="words"></param> /// <returns></returns> public Keys WordsToKeys(string words) { var wordArr = words.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var amount = wordArr.Length; if (amount != 24 && amount != 48) { throw new ArgumentException("there should be 24 or 48 words"); } var fixedWords = string.Join(" ", SubArray(wordArr, 0, 24)); BIP39 bip39 = new BIP39(fixedWords, "", BIP39.Language.English); var seed = bip39.EntropyBytes; Rebex.Security.Cryptography.Ed25519 ed25519 = new Rebex.Security.Cryptography.Ed25519(); ed25519.FromSeed(seed); var secretKey = ed25519.GetPrivateKey(); var publicKey = ed25519.GetPublicKey(); var _public = Convert.ToBase64String(publicKey) + ".ed25519"; var _private = Convert.ToBase64String(secretKey) + ".ed25519"; var keys = new Keys { Curve = "ed25519", Public = _public, Private = _private, ID = "@" + _public, }; return(keys); }
public Key(string seed = null) { _ed25519 = new Rebex.Security.Cryptography.Ed25519(); _sha256 = new SHA256Managed(); _ed25519.FromSeed( _sha256.ComputeHash(string.IsNullOrEmpty(seed) ? GetSeedKey() : Encoding.UTF8.GetBytes(seed))); _publicKey = _ed25519.GetPublicKey(); _privateKey = _ed25519.GetPrivateKey(); }
private void button1_Click(object sender, EventArgs e) { var timestamp = System.DateTime.UtcNow.ToFileTimeUtc().ToString(); using (var hmacsha256 = new HMACSHA256(GetKey())) { hmacsha256.Initialize(); var hash = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(textBox1.Text)); var ed25519 = new Rebex.Security.Cryptography.Ed25519(); ed25519.FromSeed(hash); label1.Text = $@"Key:{ByteToString( ed25519.GetPrivateKey())} Hash:{ByteToString(hash)}"; } }
public static Ed25519Signature Sign(byte[] payload, Ed25519Seed seed) { var ed25519 = new Rebex.Security.Cryptography.Ed25519(); ed25519.FromSeed(seed.SecretKey.Take(32).ToArray()); var signature = ed25519.SignMessage(payload); return(new Ed25519Signature { PublicKey = seed.KeyPair.PublicKey.ToHex(), Signature = signature.ToHex() }); }