コード例 #1
0
  @Test
  public void encryptNoRecipients() throws CoseException, InvalidCipherTextException, Exception {
    EncryptMessage msg = new EncryptMessage();

    thrown.expect(CoseException.class);
    thrown.expectMessage("No recipients supplied");
    msg.addAttribute(HeaderKeys.Algorithm, AlgorithmID.AES_GCM_128.AsCBOR(), Attribute.PROTECTED);
    msg.SetContent(rgbContent);
    msg.encrypt();
  }
コード例 #2
0
  @Test
  public void encryptIncorrectIV() throws CoseException, InvalidCipherTextException, Exception {
    EncryptMessage msg = new EncryptMessage();
    msg.addRecipient(recipient128);

    thrown.expect(CoseException.class);
    thrown.expectMessage("IV size is incorrect");
    msg.addAttribute(HeaderKeys.Algorithm, AlgorithmID.AES_GCM_128.AsCBOR(), Attribute.PROTECTED);
    msg.addAttribute(HeaderKeys.IV, rgbIV128, Attribute.UNPROTECTED);
    msg.SetContent(rgbContent);
    msg.encrypt();
  }
コード例 #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);
  }