本文整理汇总了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;
}
示例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);
}
}