当前位置: 首页>>代码示例>>Java>>正文


Java OpenPgpApi.ACTION_SIGN_AND_ENCRYPT属性代码示例

本文整理汇总了Java中org.openintents.openpgp.util.OpenPgpApi.ACTION_SIGN_AND_ENCRYPT属性的典型用法代码示例。如果您正苦于以下问题:Java OpenPgpApi.ACTION_SIGN_AND_ENCRYPT属性的具体用法?Java OpenPgpApi.ACTION_SIGN_AND_ENCRYPT怎么用?Java OpenPgpApi.ACTION_SIGN_AND_ENCRYPT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.openintents.openpgp.util.OpenPgpApi的用法示例。


在下文中一共展示了OpenPgpApi.ACTION_SIGN_AND_ENCRYPT属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildEncrypt__withInlineEnabled__shouldSucceed

@Test
public void buildEncrypt__withInlineEnabled__shouldSucceed() throws MessagingException {
    ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
            .setCryptoMode(CryptoMode.CHOICE_ENABLED)
            .setRecipients(Collections.singletonList(new Recipient("test", "[email protected]", "labru", -1, "key")))
            .setEnablePgpInline(true)
            .build();
    pgpMessageBuilder.setCryptoStatus(cryptoStatus);

    ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class);

    Intent returnIntent = new Intent();
    returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);

    when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class)))
            .thenReturn(returnIntent);

    Callback mockCallback = mock(Callback.class);
    pgpMessageBuilder.buildAsync(mockCallback);

    Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_KEY_ID);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_KEY_ID });
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
    assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());

    ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false));
    verifyNoMoreInteractions(mockCallback);

    MimeMessage message = captor.getValue();
    Assert.assertEquals("text/plain", message.getMimeType());
    assertTrue("message body must be BinaryTempFileBody", message.getBody() instanceof BinaryTempFileBody);
    Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) message.getBody()).getEncoding());

    assertMessageHasAutocryptHeader(message, SENDER_EMAIL, false, AUTOCRYPT_KEY_MATERIAL);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:38,代码来源:PgpMessageBuilderTest.java

示例2: buildOpenPgpApiIntent

@NonNull
private Intent buildOpenPgpApiIntent(boolean shouldSign, boolean shouldEncrypt, boolean isPgpInlineMode)
        throws MessagingException {
    Intent pgpApiIntent;
    if (shouldEncrypt) {
        if (!shouldSign) {
            throw new IllegalStateException("encrypt-only is not supported at this point and should never happen!");
        }
        // pgpApiIntent = new Intent(shouldSign ? OpenPgpApi.ACTION_SIGN_AND_ENCRYPT : OpenPgpApi.ACTION_ENCRYPT);
        pgpApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);

        long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
        if (encryptKeyIds != null) {
            pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
        }

        if(!isDraft()) {
            String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
            boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
            if (!hasRecipientAddresses) {
                throw new MessagingException("encryption is enabled, but no recipient specified!");
            }
            pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
            pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
        }
    } else {
        pgpApiIntent = new Intent(isPgpInlineMode ? OpenPgpApi.ACTION_SIGN : OpenPgpApi.ACTION_DETACHED_SIGN);
    }

    if (shouldSign) {
        pgpApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, cryptoStatus.getSigningKeyId());
    }

    pgpApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    return pgpApiIntent;
}
 
开发者ID:scoute-dich,项目名称:K9-MailClient,代码行数:36,代码来源:PgpMessageBuilder.java

示例3: buildEncrypt__withInlineEnabled__shouldSucceed

@Test
public void buildEncrypt__withInlineEnabled__shouldSucceed() throws MessagingException {
    ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
            .setCryptoMode(CryptoMode.PRIVATE)
            .setRecipients(Collections.singletonList(new Recipient("test", "[email protected]", "labru", -1, "key")))
            .setEnablePgpInline(true)
            .build();
    pgpMessageBuilder.setCryptoStatus(cryptoStatus);

    ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class);

    Intent returnIntent = new Intent();
    returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);

    when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class)))
            .thenReturn(returnIntent);

    Callback mockCallback = mock(Callback.class);
    pgpMessageBuilder.buildAsync(mockCallback);

    Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_SELF_ENCRYPT_KEY_ID });
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, false);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
    assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());

    ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false));
    verifyNoMoreInteractions(mockCallback);

    MimeMessage message = captor.getValue();
    Assert.assertEquals("text/plain", message.getMimeType());
    Assert.assertTrue("message body must be BinaryTempFileBody", message.getBody() instanceof BinaryTempFileBody);
    Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) message.getBody()).getEncoding());
}
 
开发者ID:scoute-dich,项目名称:K9-MailClient,代码行数:37,代码来源:PgpMessageBuilderTest.java

示例4: buildEncrypt__shouldSucceed

@Test
public void buildEncrypt__shouldSucceed() throws MessagingException {
    ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
            .setCryptoMode(CryptoMode.CHOICE_ENABLED)
            .setRecipients(Collections.singletonList(new Recipient("test", "[email protected]", "labru", -1, "key")))
            .build();
    pgpMessageBuilder.setCryptoStatus(cryptoStatus);

    ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class);

    Intent returnIntent = new Intent();
    returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);

    when(openPgpApi.executeApi(capturedApiIntent.capture(),
            any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);

    Callback mockCallback = mock(Callback.class);
    pgpMessageBuilder.buildAsync(mockCallback);

    Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_KEY_ID);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_KEY_ID });
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
    assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());

    ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false));
    verifyNoMoreInteractions(mockCallback);

    MimeMessage message = captor.getValue();

    Assert.assertEquals("message must be multipart/encrypted", "multipart/encrypted", message.getMimeType());

    MimeMultipart multipart = (MimeMultipart) message.getBody();
    Assert.assertEquals("multipart/encrypted must consist of two parts", 2, multipart.getCount());

    BodyPart dummyBodyPart = multipart.getBodyPart(0);
    Assert.assertEquals("first part must be pgp encrypted dummy part",
            "application/pgp-encrypted", dummyBodyPart.getContentType());
    assertContentOfBodyPartEquals("content must match the supplied detached signature",
            dummyBodyPart, "Version: 1");

    BodyPart encryptedBodyPart = multipart.getBodyPart(1);
    Assert.assertEquals("second part must be octet-stream of encrypted data",
            "application/octet-stream; name=\"encrypted.asc\"", encryptedBodyPart.getContentType());
    assertTrue("message body must be BinaryTempFileBody",
            encryptedBodyPart.getBody() instanceof BinaryTempFileBody);
    Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) encryptedBodyPart.getBody()).getEncoding());

    assertMessageHasAutocryptHeader(message, SENDER_EMAIL, false, AUTOCRYPT_KEY_MATERIAL);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:52,代码来源:PgpMessageBuilderTest.java

示例5: buildEncrypt__shouldSucceed

@Test
public void buildEncrypt__shouldSucceed() throws MessagingException {
    ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
            .setCryptoMode(CryptoMode.PRIVATE)
            .setRecipients(Collections.singletonList(new Recipient("test", "[email protected]", "labru", -1, "key")))
            .build();
    pgpMessageBuilder.setCryptoStatus(cryptoStatus);

    ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class);

    Intent returnIntent = new Intent();
    returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);

    when(openPgpApi.executeApi(capturedApiIntent.capture(),
            any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);

    Callback mockCallback = mock(Callback.class);
    pgpMessageBuilder.buildAsync(mockCallback);

    Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_SELF_ENCRYPT_KEY_ID });
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, false);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
    assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());

    ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false));
    verifyNoMoreInteractions(mockCallback);

    MimeMessage message = captor.getValue();

    Assert.assertEquals("message must be multipart/encrypted", "multipart/encrypted", message.getMimeType());

    MimeMultipart multipart = (MimeMultipart) message.getBody();
    Assert.assertEquals("multipart/encrypted must consist of two parts", 2, multipart.getCount());

    BodyPart dummyBodyPart = multipart.getBodyPart(0);
    Assert.assertEquals("first part must be pgp encrypted dummy part",
            "application/pgp-encrypted", dummyBodyPart.getContentType());
    assertContentOfBodyPartEquals("content must match the supplied detached signature",
            dummyBodyPart, "Version: 1");

    BodyPart encryptedBodyPart = multipart.getBodyPart(1);
    Assert.assertEquals("second part must be octet-stream of encrypted data",
            "application/octet-stream; name=\"encrypted.asc\"", encryptedBodyPart.getContentType());
    Assert.assertTrue("message body must be BinaryTempFileBody",
            encryptedBodyPart.getBody() instanceof BinaryTempFileBody);
    Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) encryptedBodyPart.getBody()).getEncoding());
}
 
开发者ID:scoute-dich,项目名称:K9-MailClient,代码行数:51,代码来源:PgpMessageBuilderTest.java


注:本文中的org.openintents.openpgp.util.OpenPgpApi.ACTION_SIGN_AND_ENCRYPT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。