public new CBORObject EncodeToCBORObject() { CBORObject cborBodyAttributes = null; byte[] rgbBody = null; if (m_msgToSign != null) { if (m_msgToSign.GetType() == typeof(EncryptMessage)) { EncryptMessage msg = (EncryptMessage)m_msgToSign; msg.Encrypt(); CBORObject obj = msg.EncodeToCBORObject(); if (obj[1].Type != CBORType.ByteString) { throw new Exception("Internal error"); } if (obj[3].Type != CBORType.ByteString) { throw new Exception("Internal error"); } rgbBody = obj[3].GetByteString(); cborBodyAttributes = obj[1]; } } else if (m_signerToSign != null) { CBORObject obj = m_signerToSign.EncodeToCBORObject(); } return(base.EncodeToCBORObject(cborBodyAttributes.GetByteString(), rgbBody)); }
public void encryptNoEmitContent() { EncryptMessage msg = new EncryptMessage(true, false); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, true); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), false); msg.SetContent(strContent); msg.Encrypt(rgbKey128); CBORObject cn = msg.EncodeToCBORObject(); Assert.IsTrue(cn[2].IsNull); }
public void encryptNoEmitContent() { EncryptMessage msg = new EncryptMessage(true, false); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.UNPROTECTED); msg.SetContent(strContent); Recipient r = new Recipient(key128, AlgorithmValues.Direct); msg.AddRecipient(r); msg.Encrypt(); CBORObject cn = msg.EncodeToCBORObject(); Assert.IsTrue(cn[2].IsNull); }
public void TestRoundTrip3() { EncryptMessage msg = new EncryptMessage(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.PROTECTED); msg.SetContent(rgbContent); msg.AddRecipient(recipient128); msg.Encrypt(); List <Recipient> rList = msg.RecipientList; Assert.AreEqual(rList.Count(), (1)); CBORObject rgbMsg = msg.EncodeToCBORObject(); msg = (EncryptMessage)Message.DecodeFromCBOR(rgbMsg, Tags.Encrypt); Recipient r = msg.RecipientList[0]; r.SetKey(cnKey128); byte[] contentNew = msg.Decrypt(r); CollectionAssert.AreEqual(contentNew, (rgbContent)); }