Skip to content

Commit

Permalink
feat: 敏感信息存储支持国密 TencentBlueKing#2055
Browse files Browse the repository at this point in the history
优化代码结构
  • Loading branch information
jsonwan committed Jul 28, 2023
1 parent e68f7f0 commit 66b0479
Show file tree
Hide file tree
Showing 36 changed files with 303 additions and 484 deletions.
3 changes: 3 additions & 0 deletions src/backend/commons/common-crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@

dependencies {
api project(':commons:common')
api project(':commons:common-utils')
api 'com.tencent.bk.sdk:crypto-java-sdk'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

package com.tencent.bk.job.common.crypto;

import com.tencent.bk.job.common.exception.CryptoException;
import com.tencent.bk.job.common.util.crypto.AESUtils;
import com.tencent.bk.job.common.crypto.util.AESUtils;
import com.tencent.bk.sdk.crypto.annotation.Cryptor;
import com.tencent.bk.sdk.crypto.annotation.CryptorTypeEnum;
import com.tencent.bk.sdk.crypto.cryptor.AbstractSymmetricCryptor;
import com.tencent.bk.sdk.crypto.exception.CryptoException;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;

Expand Down Expand Up @@ -92,7 +92,7 @@ public void encryptIndeed(String key, InputStream in, OutputStream out) {
key.length()
}
);
throw new com.tencent.bk.sdk.crypto.exception.CryptoException(msg.getMessage(), e);
throw new CryptoException(msg.getMessage(), e);
}
}

Expand All @@ -108,7 +108,7 @@ public void decryptIndeed(String key, InputStream in, OutputStream out) {
key.length()
}
);
throw new com.tencent.bk.sdk.crypto.exception.CryptoException(msg.getMessage(), e);
throw new CryptoException(msg.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,27 @@

package com.tencent.bk.job.common.crypto;

/**
* 非对称加密器
*/
public interface AsymmetricEncryptor extends Encryptor {
import com.tencent.bk.job.common.crypto.util.RSAUtils;
import com.tencent.bk.sdk.crypto.exception.CryptoException;
import lombok.extern.slf4j.Slf4j;

import java.security.PublicKey;

@Slf4j
public class RSAEncryptor implements Encryptor {

private final PublicKey publicKey;

public RSAEncryptor(String rsaPublicKeyBase64) {
publicKey = RSAUtils.getPublicKey(rsaPublicKeyBase64);
}

/**
* 校验消息的签名是否一致 通过公钥对消息内容进行校验signature内容(由私钥加签名)
*
* @param message 原消息内容
* @param signature 消息的签名
* @return 是否签名一致
*/
boolean verify(String message, String signature);
public String encrypt(String rawText) {
try {
return RSAUtils.encrypt(rawText, publicKey);
} catch (CryptoException e) {
log.error("Fail to encrypt", e);
return null;
}
}
}
Loading

0 comments on commit 66b0479

Please sign in to comment.