// Check RSA encription and decription with string public void TestRSAencryptDecryptString() { KeyPair keys = KeysHelper.generateRsaKeyPair(); String originalData = "Est Enim Quaedam Flere Voluptas - In girum Imus Nocte Et Consumimur Igni - 42"; byte[] dataEncoded = EncryptionHelper.encryptStringWithRsa(originalData, keys.publicKey); byte[] dataDecoded = EncryptionHelper.decryptBytesWithRsa(dataEncoded, keys.privateKey); String decodedData = Encoding.UTF8.GetString(dataDecoded); Assert.IsTrue(String.Equals(originalData, decodedData, StringComparison.InvariantCulture)); }
// Check RSA encription and decription with byte array public void TestRSAencryptDecryptByteArray() { KeyPair keys = KeysHelper.generateRsaKeyPair(); String originalData = @"Eh bien , mon prince, Genes et Lucques ne sont plus que des apanages, des 'pomestja' de la famille Buonaparte. Non, je vous préviens que si vous ne me dites pas que nous avons la guerre"; byte[] encodedOriginal = Encoding.UTF8.GetBytes(originalData); byte[] dataEncoded = EncryptionHelper.encryptBytesWithRsa(encodedOriginal, keys.publicKey); byte[] dataDecoded = EncryptionHelper.decryptBytesWithRsa(dataEncoded, keys.privateKey); String decodedData = Encoding.UTF8.GetString(dataDecoded); Assert.IsTrue(String.Equals(originalData, decodedData, StringComparison.InvariantCulture)); }
public async Task DidDocumentFromWalletJsonTest() { String lcdUrl = "http://localhost:1317"; // string didcom = "1fvwfjx2yealxyw5hktqnvm5ynljlc8jqkkd8kl"; NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: "did:com:", lcdUrl: lcdUrl); String mnemonicString = "gorilla soldier device force cupboard transfer lake series cement another bachelor fatigue royal lens juice game sentence right invite trade perfect town heavy what"; List <String> mnemonic = new List <String>(mnemonicString.Split(" ", StringSplitOptions.RemoveEmptyEntries)); Wallet wallet = Wallet.derive(mnemonic, networkInfo); // Here the mock server part... // Build the mockup server String localTestUrl1 = $"{lcdUrl}/auth/accounts/did:com:1fvwfjx2yealxyw5hktqnvm5ynljlc8jqkkd8kl"; // String localTestUrl2 = $"{lcdUrl}/identities/did:com:1fvwfjx2yealxyw5hktqnvm5ynljlc8jqkkd8kl"; var _server = new MockHttpServer(); // I need this in order to get the correct data out of the mock server Dictionary <string, object> nodeResponse1 = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.TestResources.accountResponse); // Dictionary<String, Object> nodeResponse2 = JsonConvert.DeserializeObject<Dictionary<String, Object>>(TestResources.TestResources.tumblerIdentityJson); // Initialize Server Response _server .WithService(localTestUrl1) .Api("", "GET", nodeResponse1); //_server // .WithService(localTestUrl2) // .Api("", "GET", nodeResponse2); // Link the client to the retrieval class Network HttpClient client = new HttpClient(_server); Network.client = client; KeyPair rsaKeyPair = KeysHelper.generateRsaKeyPair(); KeyPair ecKeyPair = KeysHelper.generateEcKeyPair(); List <PublicKey> pubKeys = new List <PublicKey>(); pubKeys.Add(rsaKeyPair.publicKey); pubKeys.Add(ecKeyPair.publicKey); DidDocument didDocument = DidDocumentHelper.fromWallet(wallet, pubKeys); TransactionResult results = await IdHelper.setDidDocument(didDocument, wallet); // Just to test no exception in the code Assert.AreEqual(true, true); }
// Check RSA Keys for unicity public void TestUniqueRSAKeys() { int numKeys = 20; List <KeyPair> keys = new List <KeyPair>(); for (int i = 0; i < numKeys; i++) { keys.Add(KeysHelper.generateRsaKeyPair()); } Dictionary <BigInteger, RSAPublicKey> keysModulus = new Dictionary <BigInteger, RSAPublicKey>(); keysModulus = keys.ToDictionary ( //Define key element => ((RSAPublicKey)element.publicKey).pubKey.Modulus, //Define value element => (((RSAPublicKey)element.publicKey)) ); Assert.IsTrue(keysModulus.Count == numKeys); }
// '"fromWallet()" returns a well-formed "RequestDidPowerUp" object.' public async Task WellFormedRequestDidPowerUpFromWallet() { //This is the comparison class CompareLogic compareLogic = new CompareLogic(); String lcdUrl = "http://localhost:1317"; NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: "did:com:", lcdUrl: lcdUrl); String mnemonicString = "gorilla soldier device force cupboard transfer lake series cement another bachelor fatigue royal lens juice game sentence right invite trade perfect town heavy what"; List <String> mnemonic = new List <String>(mnemonicString.Split(" ", StringSplitOptions.RemoveEmptyEntries)); Wallet wallet = Wallet.derive(mnemonic, networkInfo); Wallet pairwaisedWallet = Wallet.derive(mnemonic, networkInfo, lastDerivationPathSegment: "1"); List <StdCoin> amount = new List <StdCoin> { new StdCoin(denom: "denom", amount: "10") }; // Here the mock server part... // Build the mockup server String localTestUrl1 = $"{lcdUrl}/government/tumbler"; String localTestUrl2 = $"{lcdUrl}/identities/did:com:1fvwfjx2yealxyw5hktqnvm5ynljlc8jqkkd8kl"; var _server = new MockHttpServer(); // I need this in order to get the correct data out of the mock server Dictionary <string, object> nodeResponse1 = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.TestResources.tumblerAddressJson); Dictionary <String, Object> nodeResponse2 = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.TestResources.tumblerIdentityJson); // Initialize Server Response _server .WithService(localTestUrl1) .Api("", "GET", nodeResponse1); _server .WithService(localTestUrl2) .Api("", "GET", nodeResponse2); // Link the client to the retrieval class Network HttpClient client = new HttpClient(_server); Network.client = client; KeyPair keyPair = KeysHelper.generateRsaKeyPair(); String powerUpProof = "powerUpProof"; String uuid = Guid.NewGuid().ToString(); String encryptionKey = "encryptionKey"; RequestDidPowerUp expectedRequestDidPowerUp = new RequestDidPowerUp( claimantDid: wallet.bech32Address, amount: amount, powerUpProof: Convert.ToBase64String(Encoding.UTF8.GetBytes(powerUpProof)), uuid: uuid, encryptionKey: Convert.ToBase64String(Encoding.UTF8.GetBytes(encryptionKey)) ); RequestDidPowerUp requestDidPowerUp = await RequestDidPowerUpHelper.fromWallet( wallet, pairwaisedWallet.bech32Address, amount, (RSAPrivateKey)keyPair.privateKey ); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.claimantDid, expectedRequestDidPowerUp.claimantDid).AreEqual, true); Assert.AreEqual(requestDidPowerUp.amount.Count, expectedRequestDidPowerUp.amount.Count); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.amount[0].toJson(), expectedRequestDidPowerUp.amount[0].toJson()).AreEqual, true); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.uuid, expectedRequestDidPowerUp.uuid).AreEqual, false); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.powerUpProof, expectedRequestDidPowerUp.powerUpProof).AreEqual, false); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.encryptionKey, expectedRequestDidPowerUp.encryptionKey).AreEqual, false); }
// '"fromWallet()" returns a well-formed "RequestDidPowerUp" object.' public async Task WellFormedRequestDidPowerUpFromWallet() { //This is the comparison class CompareLogic compareLogic = new CompareLogic(); String lcdUrl = "http://url"; NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: "did:com:", lcdUrl: lcdUrl); String mnemonicString = "dash ordinary anxiety zone slot rail flavor tortoise guilt divert pet sound ostrich increase resist short ship lift town ice split payment round apology"; List <String> mnemonic = new List <String>(mnemonicString.Split(" ", StringSplitOptions.RemoveEmptyEntries)); Wallet wallet = Wallet.derive(mnemonic, networkInfo); Wallet pairwaisedWallet = Wallet.derive(mnemonic, networkInfo, lastDerivationPathSegment: "1"); List <StdCoin> amount = new List <StdCoin> { new StdCoin(denom: "denom", amount: "10") }; // Here the mock server part... // Build the mockup server String localTestUrl1 = $"{lcdUrl}/government/tumbler"; String localTestUrl2 = $"{lcdUrl}/identities/did:com:14ttg3eyu88jda8udvxpwjl2pwxemh72w0grsau"; var _server = new MockHttpServer(); // I need this in order to get the correct data out of the mock server Dictionary <string, object> nodeResponse1 = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.TestResources.tumblerAddressJson); Dictionary <String, Object> nodeResponse2 = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.TestResources.tumblerIdentityJson); // Initialize Server Response _server .WithService(localTestUrl1) .Api("", "GET", nodeResponse1); _server .WithService(localTestUrl2) .Api("", "GET", nodeResponse2); // Link the client to the retrieval class Network HttpClient client = new HttpClient(_server); Network.client = client; KeyPair keyPair = KeysHelper.generateRsaKeyPair(); String powerUpProof = "powerUpProof"; String uuid = Guid.NewGuid().ToString(); String encryptionKey = "encryptionKey"; RequestDidPowerUp expectedRequestDidPowerUp = new RequestDidPowerUp( claimantDid: wallet.bech32Address, amount: amount, powerUpProof: Convert.ToBase64String(Encoding.UTF8.GetBytes(powerUpProof)), uuid: uuid, encryptionKey: Convert.ToBase64String(Encoding.UTF8.GetBytes(encryptionKey)) ); RequestDidPowerUp requestDidPowerUp = await RequestDidPowerUpHelper.fromWallet( wallet, pairwaisedWallet.bech32Address, amount, (RSAPrivateKey)keyPair.privateKey ); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.claimantDid, expectedRequestDidPowerUp.claimantDid).AreEqual, true); Assert.AreEqual(requestDidPowerUp.amount.Count, expectedRequestDidPowerUp.amount.Count); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.amount[0].toJson(), expectedRequestDidPowerUp.amount[0].toJson()).AreEqual, true); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.uuid, expectedRequestDidPowerUp.uuid).AreEqual, false); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.powerUpProof, expectedRequestDidPowerUp.powerUpProof).AreEqual, false); Assert.AreEqual(compareLogic.Compare(requestDidPowerUp.encryptionKey, expectedRequestDidPowerUp.encryptionKey).AreEqual, false); }