示例#1
0
		internal static CipherBlock ServerCipher(BinaryReader rd, PrivateKeyByPublicKeyHash privateKeySelector)
		{
			var certificateHash = rd.ReadVarBytes();
			var iv = rd.ReadVarBytes();
			var encryptedKey = rd.ReadVarBytes();

			var privateKey = privateKeySelector(certificateHash);


			if (privateKey == null)
				throw new InvalidOperationException("You have to provide a private key");

			if (privateKey.PublicOnly)
				throw new InvalidOperationException($"The {nameof(CipherBlock)} accepts private keys only.");


			var aes = new AesCryptoServiceProvider
			{
				Padding = PaddingMode.Zeros,
				IV = iv,
				Key = new RSAOAEPKeyExchangeDeformatter(privateKey).DecryptKeyExchange(encryptedKey)
			};

			return new CipherBlock(aes, certificateHash);
		}
示例#2
0
 public static TxOutput DecodeTxOutput(Stream stream)
 {
     using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true))
     {
         return new TxOutput
         (
             value: reader.Read8Bytes(),
             scriptPublicKey: reader.ReadVarBytes().ToImmutableArray()
         );
     }
 }
示例#3
0
 public static NetworkAddressKey DecodeNetworkAddressKey(BinaryReader reader)
 {
     return new NetworkAddressKey
     (
         IPv6Address: reader.ReadVarBytes().ToImmutableArray(),
         Port: reader.ReadUInt16()
     );
 }
示例#4
0
 public static ChainedHeader DecodeChainedHeader(BinaryReader reader)
 {
     var blockHash = reader.ReadUInt256();
     return new ChainedHeader
     (
         blockHeader: DecodeBlockHeader(reader, blockHash),
         height: reader.ReadInt32(),
         totalWork: new BigInteger(reader.ReadVarBytes())
     );
 }
示例#5
0
 public static TxInput DecodeTxInput(Stream stream)
 {
     using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true))
     {
         return new TxInput
         (
             previousTxOutputKey: new TxOutputKey
             (
                 txHash: reader.Read32Bytes(),
                 txOutputIndex: reader.Read4Bytes()
             ),
             scriptSignature: reader.ReadVarBytes().ToImmutableArray(),
             sequence: reader.Read4Bytes()
         );
     }
 }
示例#6
0
 public static UnspentTx DecodeUnspentTx(BinaryReader reader)
 {
     return new UnspentTx(
         txHash: reader.ReadUInt256(),
         blockIndex: reader.ReadInt32(),
         txIndex: reader.ReadInt32(),
         outputStates: new OutputStates(
             bytes: reader.ReadVarBytes(),
             length: reader.ReadInt32())
     );
 }
示例#7
0
 public static TxOutput DecodeTxOutput(BinaryReader reader)
 {
     return new TxOutput
     (
         value: reader.ReadUInt64(),
         scriptPublicKey: reader.ReadVarBytes().ToImmutableArray()
     );
 }
示例#8
0
 public static TxInput DecodeTxInput(BinaryReader reader)
 {
     return new TxInput
     (
         previousTxOutputKey: new TxOutputKey
         (
             txHash: reader.ReadUInt256(),
             txOutputIndex: reader.ReadUInt32()
         ),
         scriptSignature: reader.ReadVarBytes().ToImmutableArray(),
         sequence: reader.ReadUInt32()
     );
 }
 public static string ReadVarString(this BinaryReader reader, int max = 0x1000000)
 {
     return(Encoding.UTF8.GetString(reader.ReadVarBytes(max)));
 }
		internal void ReadFromStream(BinaryReader rd)
		{
			Type = rd.ReadInt64();
			Preamble = rd.ReadVarBytes();
			Data = rd.ReadVarBytes();
		}