public void WriteEncryptedApplicationData_TLS_AES_128_GCM_SHA256_ResultIsExpected(string encryptedData, string key, string iv, ulong seq, string decryptedPayload) { //Arrange var buffer = new byte[TlsBuffer.MaxRecordSize]; using var aead = Cipher.TLS_AES_128_GCM_SHA256.CreateAead(Utils.ParseHexString(iv), Utils.ParseHexString(key)); //Act var cursor = new MemoryCursor(buffer); using (TlsRecord.StartEncryptedWriting(cursor, RecordType.ApplicationData, aead, seq)) { Utils.ParseHexString(decryptedPayload).CopyTo(cursor); } //Assert Assert.Equal(encryptedData, Utils.ToHexString(cursor.PeekStart().ToArray()), true); }
public void WriteEncryptedApplicationData_TLS_AES_128_GCM_SHA256_ResultIsExpected() { //Arrange var expectedData = GetEncryptedApplicationData(); var cerificateData = GetCertificateData(); var signatureData = GetSignatureData(); var verifyData = GetVerifyData(); var encryptionData = GetEncryptionData(); var buffer = new byte[TlsBuffer.MaxRecordSize]; using var aead = Cipher.TLS_AES_128_GCM_SHA256.CreateAead(Utils.ParseHexString(encryptionData.Iv), Utils.ParseHexString(encryptionData.Key)); //Act var cursor = new MemoryCursor(buffer); using (TlsRecord.StartEncryptedWriting(cursor, RecordType.Handshake, aead, encryptionData.SeqNum)) { EncryptedExtensions.WriteEmpty(cursor); using (Certificate.StartWriting(cursor)) { CertificateEntry.Write(Utils.ParseHexString(cerificateData), cursor); } using (CertificateVerify.StartWriting(cursor, SignatureScheme.RSA_PSS_RSAE_SHA256)) { Utils.ParseHexString(signatureData).CopyTo(cursor); } using (Finished.StartWriting(cursor)) { Utils.ParseHexString(verifyData).CopyTo(cursor); } } //Assert Assert.Equal(expectedData, Utils.ToHexString(cursor.PeekStart().ToArray()), true); }