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


Java EncoderException类代码示例

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


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

示例1: send

import org.bouncycastle.util.encoders.EncoderException; //导入依赖的package包/类
/**
 * This method will take a Bytestring message and encrypt it via the member variable
 * SessionImpl's transformSending() method.  Since we are using chunks of unlimited size,
 * outgoingMessage will only contain one chunk that contains the entire encrypted message.
 * After the message is encrypted, it is then sent to the inner Session object.
 */

@Override
public synchronized boolean send(Bytestring message) throws InterruptedException, IOException {
    String[] outgoingMessage;
    try {
        synchronized (lock) {
            outgoingMessage = sessionImpl.transformSending(new String(Hex.encode(message.bytes)), null);
        }
    } catch (OtrException | EncoderException e) {
        this.close();
        return false;
    }

    for (String part : outgoingMessage) {
        s.send(new Bytestring(part.getBytes()));
    }
    return true;
}
 
开发者ID:DanielKrawisz,项目名称:Shufflepuff,代码行数:25,代码来源:OtrChannel.java

示例2: protect

import org.bouncycastle.util.encoders.EncoderException; //导入依赖的package包/类
/**
 * Returns the encrypted cipher text.
 *
 * @param unprotectedValue the sensitive value
 * @return the value to persist in the {@code nifi.properties} file
 * @throws SensitivePropertyProtectionException if there is an exception encrypting the value
 */
@Override
public String protect(String unprotectedValue) throws SensitivePropertyProtectionException {
    if (unprotectedValue == null || unprotectedValue.trim().length() == 0) {
        throw new IllegalArgumentException("Cannot encrypt an empty value");
    }

    // Generate IV
    byte[] iv = generateIV();
    if (iv.length < IV_LENGTH) {
        throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes");
    }

    try {
        // Initialize cipher for encryption
        cipher.init(Cipher.ENCRYPT_MODE, this.key, new IvParameterSpec(iv));

        byte[] plainBytes = unprotectedValue.getBytes(StandardCharsets.UTF_8);
        byte[] cipherBytes = cipher.doFinal(plainBytes);
        logger.info(getName() + " encrypted a sensitive value successfully");
        return base64Encode(iv) + DELIMITER + base64Encode(cipherBytes);
        // return Base64.toBase64String(iv) + DELIMITER + Base64.toBase64String(cipherBytes);
    } catch (BadPaddingException | IllegalBlockSizeException | EncoderException | InvalidAlgorithmParameterException | InvalidKeyException e) {
        final String msg = "Error encrypting a protected value";
        logger.error(msg, e);
        throw new SensitivePropertyProtectionException(msg, e);
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:35,代码来源:AESSensitivePropertyProvider.java


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