forked from TencentBlueKing/bk-job
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 敏感信息存储支持国密 TencentBlueKing#2055
升级SDK版本,支持非对称加密
- Loading branch information
Showing
16 changed files
with
154 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/backend/commons/common/src/main/java/com/tencent/bk/job/common/encrypt/RSACryptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. | ||
* | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. | ||
* | ||
* License for BK-JOB蓝鲸智云作业平台: | ||
* -------------------------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bk.job.common.encrypt; | ||
|
||
import com.tencent.bk.job.common.exception.CryptoException; | ||
import com.tencent.bk.job.common.util.crypto.RSAUtils; | ||
import com.tencent.bk.sdk.crypto.annotation.Cryptor; | ||
import com.tencent.bk.sdk.crypto.annotation.CryptorTypeEnum; | ||
import com.tencent.bk.sdk.crypto.cryptor.AbstractASymmetricCryptor; | ||
import org.slf4j.helpers.FormattingTuple; | ||
import org.slf4j.helpers.MessageFormatter; | ||
|
||
import java.security.PrivateKey; | ||
import java.security.PublicKey; | ||
|
||
/** | ||
* 使用RSA的加密实现 | ||
*/ | ||
@Cryptor(name = JobCryptorNames.RSA, type = CryptorTypeEnum.ASYMMETRIC) | ||
public class RSACryptor extends AbstractASymmetricCryptor { | ||
@Override | ||
public byte[] encrypt(PublicKey publicKey, byte[] message) { | ||
try { | ||
return RSAUtils.encryptToBytes(message, publicKey); | ||
} catch (Exception e) { | ||
FormattingTuple msg = MessageFormatter.format( | ||
"Fail to encrypt using RSA, publicKey.len={}, message.len={}", | ||
publicKey.getEncoded().length, | ||
message.length | ||
); | ||
throw new CryptoException(msg.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public byte[] decrypt(PrivateKey privateKey, byte[] encryptedMessage) { | ||
try { | ||
return RSAUtils.decryptToBytes(encryptedMessage, privateKey); | ||
} catch (Exception e) { | ||
FormattingTuple msg = MessageFormatter.format( | ||
"Fail to decrypt using RSA, privateKey.len={}, encryptedMessage.len={}", | ||
privateKey.getEncoded().length, | ||
encryptedMessage.length | ||
); | ||
throw new CryptoException(msg.getMessage(), e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.../src/main/resources/META-INF/services/com.tencent.bk.sdk.crypto.cryptor.ASymmetricCryptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.tencent.bk.job.common.encrypt.RSACryptor |
1 change: 1 addition & 0 deletions
1
...n/src/main/resources/META-INF/services/com.tencent.bk.sdk.crypto.cryptor.SymmetricCryptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.tencent.bk.job.common.encrypt.AESCryptor |
2 changes: 0 additions & 2 deletions
2
...ommon/src/main/resources/META-INF/services/com.tencent.bk.sdk.gm.cryptor.SymmetricCryptor
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters