-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEncodingTest.cs
More file actions
58 lines (45 loc) · 1.85 KB
/
EncodingTest.cs
File metadata and controls
58 lines (45 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using NUnit.Framework;
using Substrate.NetApi;
using System;
using System.IO;
namespace Substrate.NET.Wallet.Test
{
public class EncodingTest
{
private Random _random;
[SetUp]
public void Setup()
{
SystemInteraction.ReadData = f => File.ReadAllText(Path.Combine(Environment.CurrentDirectory, f));
SystemInteraction.DataExists = f => File.Exists(Path.Combine(Environment.CurrentDirectory, f));
SystemInteraction.ReadPersistent = f => File.ReadAllText(Path.Combine(Environment.CurrentDirectory, f));
SystemInteraction.PersistentExists = f => File.Exists(Path.Combine(Environment.CurrentDirectory, f));
SystemInteraction.Persist = (f, c) => File.WriteAllText(Path.Combine(Environment.CurrentDirectory, f), c);
_random = new Random();
}
[Test]
public void EncryptionTest()
{
var origData = new byte[_random.Next(10, 500)];
_random.NextBytes(origData);
var salt = new byte[32];
_random.NextBytes(salt);
var encryptedData = Wallet.Encrypt(origData, "aA1234dd", salt);
var reprData = Wallet.Decrypt(encryptedData, "aA1234dd", salt);
Assert.AreEqual(origData, reprData);
}
[Test]
public void EncryptionSaltTest()
{
var address = "5CcaF7yE6YU67TyPHjSwd9DKiVBTAS2AktdxNG3DeLYs63gF";
var seed = new byte[16];
_random.NextBytes(seed);
var hash = new byte[16];
_random.NextBytes(hash);
var salt = Wallet.GetSalt(Utils.GetPublicKeyFrom(address), hash);
var encodedData = Wallet.Encrypt(seed, "aA1234dd", salt);
var reprData = Wallet.Decrypt(encodedData, "aA1234dd", salt);
Assert.AreEqual(seed, reprData);
}
}
}