Ejemplo n.º 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();
  }
Ejemplo n.º 2
0
  @Test
  public void encryptNoAlgorithm() throws CoseException, InvalidCipherTextException, Exception {
    EncryptMessage msg = new EncryptMessage();
    msg.addRecipient(recipient128);

    thrown.expect(CoseException.class);
    thrown.expectMessage("No Algorithm Specified");
    msg.SetContent(rgbContent);
    msg.encrypt();
  }
Ejemplo n.º 3
0
  @Test
  public void testGetRecipientCount() {
    EncryptMessage msg = new EncryptMessage();

    assertEquals(msg.getRecipientCount(), 0);

    Recipient r = new Recipient();
    msg.addRecipient(r);
    assertEquals(msg.getRecipientCount(), 1);
  }
Ejemplo n.º 4
0
  @Test
  public void encryptUnsupportedAlgorithm()
      throws CoseException, InvalidCipherTextException, Exception {
    EncryptMessage msg = new EncryptMessage();
    msg.addRecipient(recipient128);

    thrown.expect(CoseException.class);
    thrown.expectMessage("Unsupported Algorithm Specified");
    msg.addAttribute(HeaderKeys.Algorithm, AlgorithmID.HMAC_SHA_256.AsCBOR(), Attribute.PROTECTED);
    msg.SetContent(rgbContent);
    msg.encrypt();
  }
Ejemplo n.º 5
0
  @Test
  public void encryptUnknownAlgorithm()
      throws CoseException, InvalidCipherTextException, Exception {
    EncryptMessage msg = new EncryptMessage();
    msg.addRecipient(recipient128);

    thrown.expect(CoseException.class);
    thrown.expectMessage("Unknown Algorithm Specified");
    msg.addAttribute(HeaderKeys.Algorithm, CBORObject.FromObject("Unknown"), Attribute.PROTECTED);
    msg.SetContent(rgbContent);
    msg.encrypt();
  }
Ejemplo n.º 6
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);
  }
Ejemplo n.º 7
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();
  }