public Certificate(ByteBuffer payload, AsymmetricKey publicKey, AsymmetricKey theCAPrivateKey) { PIsValid = false; SignatureByteSize = 0; if (payload.GetBufferSize() > MaxPayloadSize || !publicKey.IsValid()) { return; } var thePublicKey = PublicKey.GetPublicKey(); var packet = new PacketStream(); packet.Write(payload); packet.Write(thePublicKey); SignatureByteSize = packet.GetBytePosition(); packet.SetBytePosition(SignatureByteSize); var theSignedBytes = new ByteBuffer(packet.GetBuffer(), packet.GetBytePosition()); Signature = theCAPrivateKey.HashAndSign(theSignedBytes); packet.Write(Signature); SetBuffer(packet.GetBuffer(), packet.GetBytePosition()); }
public ByteBuffer ComputeSharedSecretKey(AsymmetricKey publicKey) { if (publicKey.GetKeySize() != GetKeySize() || !PHasPrivateKey) { return(null); } throw new NotImplementedException(); var hash = new SHA256Managed().ComputeHash(StaticCryptoBuffer, 0, (int)StaticCryptoBufferSize); return(new ByteBuffer(hash, 32)); }
public void Parse() { var aStream = new BitStream(GetBuffer(), GetBufferSize()); PayLoad = new ByteBuffer(0U); aStream.Read(PayLoad); PublicKey = new AsymmetricKey(aStream); Signature = new ByteBuffer(0U); SignatureByteSize = aStream.GetBytePosition(); aStream.SetBytePosition(SignatureByteSize); aStream.Read(Signature); if (aStream.IsValid() && GetBufferSize() == aStream.GetBytePosition() && PublicKey.IsValid()) { PIsValid = true; } }
public void SetPrivateKey(AsymmetricKey theKey) { PrivateKey = theKey; }
public virtual bool ValidatePublicKey(AsymmetricKey theKey, bool isInitiator) { return(true); }
public bool Validate(AsymmetricKey signatoryPublicKey) { return(PIsValid && signatoryPublicKey.VerifySignature(new ByteBuffer(GetBuffer(), SignatureByteSize), Signature)); }