-
Notifications
You must be signed in to change notification settings - Fork 67
feat: Add Bearer Token Support with SM4 Encryption, Improve Streaming Responses and Fix Service Error Codes #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b88ee1b
feat: add rag
lu-yg 3f442ea
feat: add rag API
lu-yg 0d8fc8d
feat: add rag API
lu-yg 369a4f5
feat: add rag API
lu-yg 864256f
feat: add rag API
lu-yg b2ce522
feat: modify ragConfig
lu-yg aee9c38
feat: add tinyengine docs
lu-yg ca68c38
feat: modify Dockerfile
lu-yg 316f90d
feat: modify Dockerfile
lu-yg 592f754
fix: modify docker-compose
lu-yg 8bc8564
fix: modeify dockerfile
lu-yg bdaf93f
fix: modify ChatRequest
lu-yg f0cb1e2
fix: Remove Alibailian related code
lu-yg a8e4d3a
fix: Modify code format
lu-yg 49a6fb2
Merge branch 'feat/rag' of github.com:lu-yg/tiny-engine-backend-java …
lu-yg 9112d23
Merge branch 'opentiny:develop' into feat/rag
lu-yg a496e97
fix: modify AI API
lu-yg 2e502df
fix: modify AI API
lu-yg 08cb468
fix: modify AI API
lu-yg f662824
fix: modify AI API
lu-yg a1af442
fix: modify AI API
lu-yg 4fa1751
fix: modify AI API
lu-yg f689e21
fix: modify AI API
lu-yg 21c5fe8
Merge branch 'feat/rag' of github.com:lu-yg/tiny-engine-backend-java …
lu-yg a3217fa
fix: modify AI API
lu-yg eae4093
fix: modify AI API
lu-yg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
base/src/main/java/com/tinyengine/it/common/utils/SM4Utils.java
This file contains hidden or 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,71 @@ | ||
| package com.tinyengine.it.common.utils; | ||
|
|
||
| import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
| import javax.crypto.Cipher; | ||
| import javax.crypto.KeyGenerator; | ||
| import javax.crypto.SecretKey; | ||
| import javax.crypto.spec.SecretKeySpec; | ||
| import java.security.SecureRandom; | ||
| import java.security.Security; | ||
| import java.util.Base64; | ||
|
|
||
| public class SM4Utils { | ||
|
|
||
| static { | ||
| Security.addProvider(new BouncyCastleProvider()); | ||
| } | ||
|
|
||
| private static final String ALGORITHM = "SM4"; | ||
| private static final String TRANSFORMATION_ECB = "SM4/ECB/PKCS5Padding"; | ||
| private static final int KEY_SIZE = 128; | ||
|
|
||
| /** | ||
| * 生成 SM4 密钥 | ||
| */ | ||
| public static String generateKeyBase64() throws Exception { | ||
| byte[] key = generateKey(); | ||
| return Base64.getEncoder().encodeToString(key); | ||
| } | ||
|
|
||
| public static byte[] generateKey() throws Exception { | ||
| KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM, "BC"); | ||
| kg.init(KEY_SIZE, new SecureRandom()); | ||
| SecretKey secretKey = kg.generateKey(); | ||
| return secretKey.getEncoded(); | ||
| } | ||
|
|
||
| /** | ||
| * ECB 模式加密 - 只加密API密钥值 (Base64 结果) | ||
| */ | ||
| public static String encryptECB(String apiKey, String base64Key) throws Exception { | ||
| byte[] key = Base64.getDecoder().decode(base64Key); | ||
| byte[] encrypted = encryptECB(apiKey.getBytes("UTF-8"), key); | ||
| return Base64.getEncoder().encodeToString(encrypted); | ||
| } | ||
|
|
||
| /** | ||
| * ECB 模式解密 - 直接返回API密钥 | ||
| */ | ||
| public static String decryptECB(String encryptedBase64, String base64Key) throws Exception { | ||
| byte[] key = Base64.getDecoder().decode(base64Key); | ||
| byte[] encrypted = Base64.getDecoder().decode(encryptedBase64); | ||
| byte[] decrypted = decryptECB(encrypted, key); | ||
| return new String(decrypted, "UTF-8"); | ||
| } | ||
|
|
||
| // ECB 模式的底层方法保持不变 | ||
| private static byte[] encryptECB(byte[] data, byte[] key) throws Exception { | ||
| SecretKeySpec secretKeySpec = new SecretKeySpec(key, ALGORITHM); | ||
| Cipher cipher = Cipher.getInstance(TRANSFORMATION_ECB, "BC"); | ||
| cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); | ||
| return cipher.doFinal(data); | ||
| } | ||
|
|
||
| private static byte[] decryptECB(byte[] encryptedData, byte[] key) throws Exception { | ||
| SecretKeySpec secretKeySpec = new SecretKeySpec(key, ALGORITHM); | ||
| Cipher cipher = Cipher.getInstance(TRANSFORMATION_ECB, "BC"); | ||
| cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); | ||
| return cipher.doFinal(encryptedData); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
base/src/main/java/com/tinyengine/it/model/dto/AiToken.java
This file contains hidden or 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,33 @@ | ||
| /** | ||
| * Copyright (c) 2023 - present TinyEngine Authors. | ||
| * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license. | ||
| * | ||
| * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||
| * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||
| * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||
| * | ||
| */ | ||
|
|
||
| package com.tinyengine.it.model.dto; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| /** | ||
| * The type Ai token. | ||
| * | ||
| * @since 2025-11-27 | ||
| */ | ||
|
|
||
| @Data | ||
| public class AiToken { | ||
| String token; | ||
|
|
||
| public AiToken(String token) { | ||
| this.token = token; | ||
| } | ||
| public AiToken(){ | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.