示例#1
0
        public void Decrypt_FormatExceptionTest(string encrypted, string expError)
        {
            using BIP0038 bip = new BIP0038();
            Exception ex = Assert.Throws <FormatException>(() => bip.Decrypt(encrypted, "wrong pass!", out _));

            Assert.Contains(expError, ex.Message);
        }
示例#2
0
        public void Decrypt_DisposedExceptionTest()
        {
            BIP0038 bip = new BIP0038();

            bip.Dispose();
            Assert.Throws <ObjectDisposedException>(() => bip.Decrypt("aa", "", out bool isComp));
        }
示例#3
0
        public void EncryptTest(PrivateKey key, string pass, string expectedComp, string expectedUncomp)
        {
            using BIP0038 bip = new BIP0038();
            string actualComp   = bip.Encrypt(key, pass, true);
            string actualUncomp = bip.Encrypt(key, pass, false);

            Assert.Equal(expectedComp, actualComp);
            Assert.Equal(expectedUncomp, actualUncomp);
        }
示例#4
0
        public void DecryptTest(PrivateKey key, string pass, string encryptedComp, string encryptedUnComp)
        {
            using BIP0038 bip = new BIP0038();
            PrivateKey actualKey  = bip.Decrypt(encryptedComp, pass, out bool isComp1);
            PrivateKey actualKey2 = bip.Decrypt(encryptedUnComp, pass, out bool isComp2);

            Assert.True(isComp1);
            Assert.False(isComp2);

            byte[] expected = key.ToBytes();
            Assert.Equal(expected, actualKey.ToBytes());
            Assert.Equal(expected, actualKey2.ToBytes());
        }
示例#5
0
        public void Decrypt_NullExceptionTest()
        {
            using BIP0038 bip = new BIP0038();
            string nstr = null;

            byte[] nba = null;

            Assert.Throws <ArgumentNullException>(() => bip.Decrypt(null, "", out bool isComp));
            Assert.Throws <ArgumentNullException>(() => bip.Decrypt(" ", "", out bool isComp));
            Assert.Throws <ArgumentNullException>(() => bip.Decrypt(null, new byte[1], out bool isComp));
            Assert.Throws <ArgumentNullException>(() => bip.Decrypt(" ", new byte[1], out bool isComp));
            Assert.Throws <ArgumentNullException>(() => bip.Decrypt("aaa", nstr, out bool isComp));
            Assert.Throws <ArgumentNullException>(() => bip.Decrypt("aaa", nba, out bool isComp));
        }
示例#6
0
        public void Encrypt_String_ExceptionTest()
        {
            BIP0038    bip  = new BIP0038();
            PrivateKey k    = KeyHelper.Prv1;
            string     nstr = null;

            Exception ex = Assert.Throws <ArgumentNullException>(() => bip.Encrypt(null, "a", true));

            Assert.Contains("Private key can not be null.", ex.Message);

            ex = Assert.Throws <ArgumentNullException>(() => bip.Encrypt(k, nstr, true));
            Assert.Contains("Password can not be null or empty.", ex.Message);

            ex = Assert.Throws <ArgumentNullException>(() => bip.Encrypt(k, "", true));
            Assert.Contains("Password can not be null or empty.", ex.Message);

            bip.Dispose();
            ex = Assert.Throws <ObjectDisposedException>(() => bip.Encrypt(k, "a", true));
            Assert.Contains("Instance was disposed.", ex.Message);
        }