public async Task <string> GetEncryptionKey() { await Scatter.Connect(); var fromKey = await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO); var toKey = await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO); var r = new Random(); return(await Scatter.GetEncryptionKey(fromKey, toKey, (UInt64)r.Next())); }
public async Task <bool> SimulateSendSecretMessage() { await Scatter.Connect(); var fromKey = await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO); var toKey = await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO); var r = new Random(); var nonce = (UInt64)r.Next(); var text = "Hello crypto secret message!"; var encryptionKeyA = await Scatter.GetEncryptionKey(fromKey, toKey, nonce); var encryptionKeyABytes = UtilsHelper.HexStringToByteArray(encryptionKeyA); Console.WriteLine("FromKey: {0}", fromKey); Console.WriteLine("ToKey: {0}", toKey); Console.WriteLine("Original: {0}", text); var encrypted = CryptoHelper.AesEncrypt(encryptionKeyABytes, text); Console.WriteLine("Encrypted: {0}", Encoding.UTF8.GetString(encrypted)); //...Send over the wire... var encryptionKeyB = await Scatter.GetEncryptionKey(toKey, fromKey, nonce); var encryptionKeyBBytes = UtilsHelper.HexStringToByteArray(encryptionKeyB); Console.WriteLine("A_PVT_KEY + B_PUB_KEY: {0}", encryptionKeyA); Console.WriteLine("B_PVT_KEY + A_PUB_KEY: {0}", encryptionKeyB); var roundtrip = CryptoHelper.AesDecrypt(encryptionKeyBBytes, encrypted); Console.WriteLine("Round Trip: {0}", roundtrip); return(encryptionKeyA == encryptionKeyB); }
public async Task OneWayEncryptDecrypt() { await Scatter.Connect(); var fromKey = await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO); var toKey = await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO); var r = new Random(); var encryptionKey = await Scatter.GetEncryptionKey(fromKey, toKey, (UInt64)r.Next()); var encryptionKeyBytes = UtilsHelper.HexStringToByteArray(encryptionKey); string text = "Hello crypto secret message!"; var encrypted = CryptoHelper.AesEncrypt(encryptionKeyBytes, text); var roundtrip = CryptoHelper.AesDecrypt(encryptionKeyBytes, encrypted); Console.WriteLine("FromKey: {0}", fromKey); Console.WriteLine("ToKey: {0}", toKey); Console.WriteLine("Original: {0}", text); Console.WriteLine("Encrypted: {0}", Encoding.UTF8.GetString(encrypted)); Console.WriteLine("Round Trip: {0}", roundtrip); }
public async Task <string> GetPublicKey() { await Scatter.Connect(); return(await Scatter.GetPublicKey(ScatterConstants.Blockchains.EOSIO)); }