use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class RsaSignUtils method decrypt.
public static String decrypt(PrivateKey key, byte[] encodedText) {
ByteArrayOutputStream out = null;
try {
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
int inputLen = encodedText.length;
if (inputLen <= MAX_DECRYPT_BLOCK) {
return new String(cipher.doFinal(encodedText), StandardCharsets.UTF_8);
}
out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段解密
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
cache = cipher.doFinal(encodedText, offSet, MAX_DECRYPT_BLOCK);
} else {
cache = cipher.doFinal(encodedText, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_DECRYPT_BLOCK;
}
return new String(out.toByteArray(), StandardCharsets.UTF_8);
} catch (NoSuchAlgorithmException e) {
throw new JeesuiteBaseException(4003, "无此解密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
} catch (InvalidKeyException e) {
throw new JeesuiteBaseException(4003, "解密私钥非法,请检查");
} catch (IllegalBlockSizeException e) {
throw new JeesuiteBaseException(4003, "密文长度非法");
} catch (BadPaddingException e) {
throw new JeesuiteBaseException(4003, "密文数据已损坏");
} finally {
try {
if (out != null)
out.close();
} catch (Exception e2) {
}
}
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class RsaSignUtils method signature.
public static String signature(PrivateKey privateKey, String contents) {
try {
byte[] data = contents.getBytes(StandardCharsets.UTF_8.name());
Signature signature = Signature.getInstance(SIGN_ALGORITHM);
signature.initSign(privateKey);
signature.update(data);
return Base64.encodeToString(signature.sign(), false);
} catch (NoSuchAlgorithmException e) {
// TODO: handle exception
} catch (InvalidKeyException e) {
throw new JeesuiteBaseException(4003, "私钥格式错误");
} catch (SignatureException e) {
// TODO: handle exception
} catch (UnsupportedEncodingException e) {
// TODO: handle exception
}
return null;
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class MQServiceRegistryBean method startProducer.
private void startProducer(String providerName) throws Exception {
if ("rocketmq".equals(providerName)) {
producer = new RocketProducerAdapter();
} else if ("cmq".equals(providerName)) {
producer = new CMQProducerAdapter();
} else if ("memoryqueue".equals(providerName)) {
producer = new MemoryQueueProducerAdapter();
} else if ("redis".equals(providerName)) {
producer = new RedisProducerAdapter(redisTemplate);
} else {
throw new JeesuiteBaseException("NOT_SUPPORT[providerName]:" + providerName);
}
producer.start();
logger.info("MQ_PRODUCER started -> groupName:{},providerName:{}", MQContext.getGroupName(), providerName);
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class MultiRouteDataSource method determineTargetDataSource.
protected DataSource determineTargetDataSource() {
String lookupKey = currentDataSourceKey();
DataSource dataSource = targetDataSources.get(lookupKey);
if (dataSource == null) {
throw new JeesuiteBaseException("Cannot determine target DataSource for lookup key [" + lookupKey + "]");
}
return dataSource;
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class AliyunProvider method createBucket.
@Override
public void createBucket(String bucketName, boolean isPrivate) {
if (ossClient.doesBucketExist(bucketName)) {
throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
}
CreateBucketRequest request = new CreateBucketRequest(bucketName);
if (isPrivate) {
request.setCannedACL(CannedAccessControlList.Private);
} else {
request.setCannedACL(CannedAccessControlList.PublicRead);
}
ossClient.createBucket(request);
}
Aggregations