• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DecoderException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bouncycastle.util.encoders.DecoderException的典型用法代码示例。如果您正苦于以下问题:Java DecoderException类的具体用法?Java DecoderException怎么用?Java DecoderException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: setPrivateKeyFromPKCS8

import org.bouncycastle.util.encoders.DecoderException; //导入依赖的package包/类
public JettyKeystoreConvertorBuilder setPrivateKeyFromPKCS8(InputStream inputStream, String algorithm) throws JettyKeystoreException {
    try {
        String contentKeyFile = IOUtils.toString(inputStream);

        Matcher contentKeyMatcher = PRIVATE_KEY_PATTERN.matcher(contentKeyFile);

        String contentKey;
        if (contentKeyMatcher.find()) {
            contentKey = contentKeyMatcher.group(1);
        } else {
            contentKey = contentKeyFile;
        }

        byte[] decodedKeyFile = Base64.decode(contentKey);

        KeyFactory keyFactory = KeyFactory.getInstance(algorithm);

        PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(decodedKeyFile);
        privateKey = keyFactory.generatePrivate(privateKeySpec);

        return this;

    } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | DecoderException e) {
        throw new JettyKeystoreException(JettyKeystoreException.ERROR_LOAD_PRIVATE_KEY_PKCS8, "Can not load private key (PKCS8)", e);
    }
}
 
开发者ID:teknux-org,项目名称:jetty-bootstrap,代码行数:27,代码来源:JettyKeystoreConvertorBuilder.java


示例2: unprotect

import org.bouncycastle.util.encoders.DecoderException; //导入依赖的package包/类
/**
 * Returns the decrypted plaintext.
 *
 * @param protectedValue the cipher text read from the {@code nifi.properties} file
 * @return the raw value to be used by the application
 * @throws SensitivePropertyProtectionException if there is an error decrypting the cipher text
 */
@Override
public String unprotect(String protectedValue) throws SensitivePropertyProtectionException {
    if (protectedValue == null || protectedValue.trim().length() < MIN_CIPHER_TEXT_LENGTH) {
        throw new IllegalArgumentException("Cannot decrypt a cipher text shorter than " + MIN_CIPHER_TEXT_LENGTH + " chars");
    }

    if (!protectedValue.contains(DELIMITER)) {
        throw new IllegalArgumentException("The cipher text does not contain the delimiter " + DELIMITER + " -- it should be of the form Base64(IV) || Base64(cipherText)");
    }

    protectedValue = protectedValue.trim();

    final String IV_B64 = protectedValue.substring(0, protectedValue.indexOf(DELIMITER));
    byte[] iv = Base64.decode(IV_B64);
    if (iv.length < IV_LENGTH) {
        throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes");
    }

    String CIPHERTEXT_B64 = protectedValue.substring(protectedValue.indexOf(DELIMITER) + 2);

    // Restore the = padding if necessary to reconstitute the GCM MAC check
    if (CIPHERTEXT_B64.length() % 4 != 0) {
        final int paddedLength = CIPHERTEXT_B64.length() + 4 - (CIPHERTEXT_B64.length() % 4);
        CIPHERTEXT_B64 = StringUtils.rightPad(CIPHERTEXT_B64, paddedLength, '=');
    }

    try {
        byte[] cipherBytes = Base64.decode(CIPHERTEXT_B64);

        cipher.init(Cipher.DECRYPT_MODE, this.key, new IvParameterSpec(iv));
        byte[] plainBytes = cipher.doFinal(cipherBytes);
        logger.debug(getName() + " decrypted a sensitive value successfully");
        return new String(plainBytes, StandardCharsets.UTF_8);
    } catch (BadPaddingException | IllegalBlockSizeException | DecoderException | InvalidAlgorithmParameterException | InvalidKeyException e) {
        final String msg = "Error decrypting a protected value";
        logger.error(msg, e);
        throw new SensitivePropertyProtectionException(msg, e);
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:47,代码来源:AESSensitivePropertyProvider.java


示例3: testGetOSCPInvalid

import org.bouncycastle.util.encoders.DecoderException; //导入依赖的package包/类
@Test
public void testGetOSCPInvalid() {
    try {
        // The encoded OCSP request is missing some chars at the end and is therefore invalid
        mvc.perform(get("/x509/api/certificates/ocsp/urn:mrn:mcl:ca:maritimecloud-idreg/MFUwUzBRME8wTTAJBgUrDgMCGgUABBQ6UIqQ34%2BgN2srrAjL6PckJ0ELZQQUxE5nZxstKKPxT9ruhJjPzxpwfFUCFCPUaD%2Fh4aw7GY%2F7bjSdgGf").header("Origin", "bla"));
        assertTrue("This shold not be reached, an exception should be thrown!", false);
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof DecoderException);
    }
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:11,代码来源:CertificateControllerTests.java


示例4: invalidTest

import org.bouncycastle.util.encoders.DecoderException; //导入依赖的package包/类
private void invalidTest(String data)
{
    try
    {
        UrlBase64.decode(data);
    }
    catch (DecoderException e)
    {
        return;
    }

    fail("invalid String data parsed");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:14,代码来源:UrlBase64Test.java


示例5: invalidTest

import org.bouncycastle.util.encoders.DecoderException; //导入依赖的package包/类
private void invalidTest(String data)
{
    try
    {
        Hex.decode(data);
    }
    catch (DecoderException e)
    {
        return;
    }

    fail("invalid String data parsed");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:14,代码来源:HexTest.java


示例6: invalidTest

import org.bouncycastle.util.encoders.DecoderException; //导入依赖的package包/类
private void invalidTest(String data)
{
    try
    {
        Base64.decode(data);
    }
    catch (DecoderException e)
    {
        return;
    }

    fail("invalid String data parsed");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:14,代码来源:Base64Test.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ChangedEvent类代码示例发布时间:2022-05-23
下一篇:
Java Currency类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap