Search in sources :

Example 1 with JeesuiteBaseException

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) {
        }
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) SignatureException(java.security.SignatureException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with JeesuiteBaseException

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;
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Signature(java.security.Signature) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 3 with JeesuiteBaseException

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);
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) CMQProducerAdapter(com.mendmix.amqp.qcloud.cmq.CMQProducerAdapter) RocketProducerAdapter(com.mendmix.amqp.rocketmq.RocketProducerAdapter) RedisProducerAdapter(com.mendmix.amqp.redis.RedisProducerAdapter) MemoryQueueProducerAdapter(com.mendmix.amqp.memoryqueue.MemoryQueueProducerAdapter)

Example 4 with JeesuiteBaseException

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;
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) AbstractDataSource(org.springframework.jdbc.datasource.AbstractDataSource) DataSource(javax.sql.DataSource)

Example 5 with JeesuiteBaseException

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);
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest)

Aggregations

JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)44 IOException (java.io.IOException)13 CObjectMetadata (com.mendmix.cos.CObjectMetadata)4 CUploadResult (com.mendmix.cos.CUploadResult)4 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Request (okhttp3.Request)4 ApiInfo (com.mendmix.common.model.ApiInfo)2 WrapperResponse (com.mendmix.common.model.WrapperResponse)2 BizSystemModule (com.mendmix.gateway.model.BizSystemModule)2 COSObject (com.qcloud.cos.model.COSObject)2 QiniuException (com.qiniu.common.QiniuException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 Map (java.util.Map)2