Esempio n. 1
0
  @Test
  public void encryptDecodeWrongBasis() throws CoseException {
    CBORObject obj = CBORObject.NewMap();

    thrown.expect(CoseException.class);
    thrown.expectMessage("Message is not a COSE security Message");

    byte[] rgb = obj.EncodeToBytes();
    Message msg = Message.DecodeFromBytes(rgb, MessageTag.Encrypt);
  }
Esempio n. 2
0
  @Test
  public void encryptDecodeWrongCount() throws CoseException {
    CBORObject obj = CBORObject.NewArray();
    obj.Add(CBORObject.False);

    thrown.expect(CoseException.class);
    thrown.expectMessage("Invalid Encrypt structure");

    byte[] rgb = obj.EncodeToBytes();
    Message msg = Message.DecodeFromBytes(rgb, MessageTag.Encrypt);
  }
Esempio n. 3
0
  /** Test of Decrypt method, of class Encrypt0Message. */
  @Test
  public void testRoundTrip() throws Exception {
    System.out.println("Round Trip");
    EncryptMessage msg = new EncryptMessage();
    msg.addAttribute(HeaderKeys.Algorithm, AlgorithmID.AES_GCM_128.AsCBOR(), Attribute.PROTECTED);
    msg.addAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attribute.PROTECTED);
    msg.SetContent(rgbContent);
    msg.addRecipient(recipient128);
    msg.encrypt();

    List<Recipient> rList = msg.getRecipientList();
    assertEquals(rList.size(), 1);

    byte[] rgbMsg = msg.EncodeToBytes();

    msg = (EncryptMessage) Message.DecodeFromBytes(rgbMsg, MessageTag.Encrypt);
    Recipient r = msg.getRecipient(0);
    r.SetKey(cnKey128);
    byte[] contentNew = msg.decrypt(r);

    assertArrayEquals(rgbContent, contentNew);
  }