public static void Test_BlockchainWithDocumentsSignedAndGlobalSignature() { // Blockchain with the content having double signature and the block closure is guaranteed by digital signature var rsa = new System.Security.Cryptography.RSACryptoServiceProvider(); var publicKeyBase64 = Convert.ToBase64String(rsa.ExportCspBlob(false)); var blocks = new Blockchain(new[] { publicKeyBase64 }, "Webmaster", "Phrases", Blockchain.BlockchainType.Binary, Blockchain.BlockSynchronization.AddInLocalAndSync, true); var test = blocks.Validate(); bool isValid; var block1 = new Blockchain.Block(blocks, "Hi my friends, I have a message for you"); var signature = rsa.SignHash(block1.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block1.AddBodySignature(publicKeyBase64, signature, false); // Add signature to body signature = rsa.SignHash(block1.CalculateChecksumBytes(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block1.AddBlockSignature(signature); // Close the block with the digital signature var block2 = new Blockchain.Block(blocks, "This is a message number 2, signed"); signature = rsa.SignHash(block2.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block2.AddBodySignature(publicKeyBase64, signature, false); // Add signature to body signature = rsa.SignHash(block2.CalculateChecksumBytes(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block2.AddBlockSignature(signature); // Close the block with the digital signature var block3 = new Blockchain.Block(blocks, "In the last block I added the last message"); signature = rsa.SignHash(block3.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block3.AddBodySignature(publicKeyBase64, signature, false); // Add signature to body signature = rsa.SignHash(block3.CalculateChecksumBytes(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block3.AddBlockSignature(signature); // Close the block with the digital signature var blockError = blocks.Validate(); // 0 = no error var lastBlock = blocks.GetLastBlock(); }
public static void Test_BlockchainWithDocumentsSignedAndGlobalSignature() { // Blockchain with the content having double signature and the block closure is guaranteed by digital signature System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider(); var PublicKeyBase64 = Convert.ToBase64String(RSA.ExportCspBlob(false)); Blockchain Blocks = new Blockchain(PublicKeyBase64, "Webmaster", "Phrases", Blockchain.BlockchainType.Binary, true); var Test = Blocks.Validate(); byte[] Signature; bool IsValid; Blockchain.Block Block1 = new Blockchain.Block(Blocks, "Hi my friends, I have a message for you"); Signature = RSA.SignHash(Block1.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block1.AddBodySignature(PublicKeyBase64, Signature, false); // Add signature to body Signature = RSA.SignHash(Block1.CalculateChecksumBytes(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block1.AddBlockSignature(Signature); // Close the block with the digital signature Blockchain.Block Block2 = new Blockchain.Block(Blocks, "This is a message number 2, signed"); Signature = RSA.SignHash(Block2.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block2.AddBodySignature(PublicKeyBase64, Signature, false); // Add signature to body Signature = RSA.SignHash(Block2.CalculateChecksumBytes(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block2.AddBlockSignature(Signature); // Close the block with the digital signature Blockchain.Block Block3 = new Blockchain.Block(Blocks, "In the last block I added the last message"); Signature = RSA.SignHash(Block3.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block3.AddBodySignature(PublicKeyBase64, Signature, false); // Add signature to body Signature = RSA.SignHash(Block3.CalculateChecksumBytes(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block3.AddBlockSignature(Signature); // Close the block with the digital signature int BlockError = Blocks.Validate(); // 0 = no error var LastBlock = Blocks.GetLastBlock(); }
private static void ActionSync(string xmlObject, long timestamp) { if (!Converter.XmlToObject(xmlObject, typeof(Blockchain.Block.DataVector), out var objDataVector)) { return; } var dataVector = (Blockchain.Block.DataVector)objDataVector; var block = new Blockchain.Block(dataVector.Blockchain, dataVector.Data, new DateTime(timestamp)); }
public static void Test_SimpleBlockchain() { // Simple blockchain var blocks = new Blockchain("Webmaster", "Phrases", Blockchain.BlockchainType.Binary, Blockchain.BlockSynchronization.AddInLocalAndSync, false); var test = blocks.Validate(); var block1 = new Blockchain.Block(blocks, "Hi my friends, I have a message for you"); var block2 = new Blockchain.Block(blocks, "This is a message number 2"); var block3 = new Blockchain.Block(blocks, "In the last block I added the last message"); var blockError = blocks.Validate(); // 0 = no error var lastBlock = blocks.GetLastBlock(); }
public static void Test_SimpleBlockchain() { // Simple blockchain Blockchain Blocks = new Blockchain("Webmaster", "Phrases", Blockchain.BlockchainType.Binary, false); var Test = Blocks.Validate(); Blockchain.Block Block1 = new Blockchain.Block(Blocks, "Hi my friends, I have a message for you"); Blockchain.Block Block2 = new Blockchain.Block(Blocks, "This is a message number 2"); Blockchain.Block Block3 = new Blockchain.Block(Blocks, "In the last block I added the last message"); int BlockError = Blocks.Validate(); // 0 = no error var LastBlock = Blocks.GetLastBlock(); }
public static void Test_BlockchainWithDocumentsSigned() { // Blockchain with the content having double signature var rsa1 = new System.Security.Cryptography.RSACryptoServiceProvider(); var publicKey1Base64 = Convert.ToBase64String(rsa1.ExportCspBlob(false)); var rsa2 = new System.Security.Cryptography.RSACryptoServiceProvider(); var publicKey2Base64 = Convert.ToBase64String(rsa2.ExportCspBlob(false)); var blocks = new Blockchain("Webmaster", "Phrases", Blockchain.BlockchainType.Binary, Blockchain.BlockSynchronization.AddInLocalAndSync, true); var test = blocks.Validate(); bool isValid; var block1 = new Blockchain.Block(blocks, "Hi my friends, I have a message for you"); var signature = rsa1.SignHash(block1.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block1.AddBodySignature(publicKey1Base64, signature, false); // Add first signature signature = rsa2.SignHash(block1.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block1.AddBodySignature(publicKey2Base64, signature, true); // Add second signature and closing the block var block2 = new Blockchain.Block(blocks, "This is a message number 2, signed"); signature = rsa1.SignHash(block2.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block2.AddBodySignature(publicKey1Base64, signature, false); // Add first signature signature = rsa2.SignHash(block2.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block2.AddBodySignature(publicKey2Base64, signature, true); var block3 = new Blockchain.Block(blocks, "In the last block I added the last message"); signature = rsa1.SignHash(block3.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block3.AddBodySignature(publicKey1Base64, signature, false); // Add first signature signature = rsa2.SignHash(block3.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); isValid = block3.AddBodySignature(publicKey2Base64, signature, true); // Add second signature and closing the block var blockError = blocks.Validate(); // 0 = no error var lastBlock = blocks.GetLastBlock(); }
public static void Test_BlockchainWithDocumentsSigned() { // Blockchain with the content having double signature System.Security.Cryptography.RSACryptoServiceProvider RSA1 = new System.Security.Cryptography.RSACryptoServiceProvider(); var PublicKey1Base64 = Convert.ToBase64String(RSA1.ExportCspBlob(false)); System.Security.Cryptography.RSACryptoServiceProvider RSA2 = new System.Security.Cryptography.RSACryptoServiceProvider(); var PublicKey2Base64 = Convert.ToBase64String(RSA2.ExportCspBlob(false)); Blockchain Blocks = new Blockchain("Webmaster", "Phrases", Blockchain.BlockchainType.Binary, true); var Test = Blocks.Validate(); byte[] Signature; bool IsValid; Blockchain.Block Block1 = new Blockchain.Block(Blocks, "Hi my friends, I have a message for you"); Signature = RSA1.SignHash(Block1.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block1.AddBodySignature(PublicKey1Base64, Signature, false); // Add first signature Signature = RSA2.SignHash(Block1.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block1.AddBodySignature(PublicKey2Base64, Signature, true); // Add second signature and closing the block Blockchain.Block Block2 = new Blockchain.Block(Blocks, "This is a message number 2, signed"); Signature = RSA1.SignHash(Block2.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block2.AddBodySignature(PublicKey1Base64, Signature, false); // Add first signature Signature = RSA2.SignHash(Block2.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block2.AddBodySignature(PublicKey2Base64, Signature, true); Blockchain.Block Block3 = new Blockchain.Block(Blocks, "In the last block I added the last message"); Signature = RSA1.SignHash(Block3.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block3.AddBodySignature(PublicKey1Base64, Signature, false); // Add first signature Signature = RSA2.SignHash(Block3.HashBody(), System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256")); IsValid = Block3.AddBodySignature(PublicKey2Base64, Signature, true); // Add second signature and closing the block int BlockError = Blocks.Validate(); // 0 = no error var LastBlock = Blocks.GetLastBlock(); }