-
Notifications
You must be signed in to change notification settings - Fork 348
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
[feature] support aes-128 & aes-256 encryption #668
Merged
binbin0325
merged 22 commits into
nacos-group:master
from
robynron:dev/chasu/kmsv3_support
Nov 8, 2023
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8a2c05d
add go.mod dependency
robynron 4953fc8
support kms v1&v3
robynron 29dfdcd
move kms_client position
robynron 5ee6e7e
both kms3.0 encrypt/decrypt and encrypted data encrypted by kms3.0 st…
robynron 500506c
modify kms version to config
robynron bc7b7ae
tiny fix
robynron 5a5d5fd
remove insecurity http
robynron 993413b
support aes-128 & aes-256 encryption
robynron 3eac86d
fix kmsV3Client init bug
robynron 901f26a
add some log
robynron 88e7186
add some log
robynron 747a99b
add samples
robynron 9217cab
fix up after binbin's review
robynron d0da7e1
fix up after binbin's review
robynron c0fe68e
tiny fix
robynron 9026b2c
tiny fix
robynron a6131bb
tiny fix
robynron ea8395f
add kms init param check
robynron dc0d19d
reverse alibaba-cloud-sdk version
robynron cecf5a0
fix go.mod conflict
robynron 0d7968f
resolve conflict with master: update some modules version
robynron 39033d9
remove some test files
robynron 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 1999-2020 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package encoding | ||
|
||
import ( | ||
"encoding/base64" | ||
"unicode/utf8" | ||
) | ||
|
||
func DecodeString2Utf8Bytes(data string) []byte { | ||
resBytes := make([]byte, 0, 8) | ||
if len(data) == 0 { | ||
return resBytes | ||
} | ||
bytesLen := 0 | ||
runes := []rune(data) | ||
for _, r := range runes { | ||
bytesLen += utf8.RuneLen(r) | ||
} | ||
resBytes = make([]byte, bytesLen) | ||
pos := 0 | ||
for _, r := range runes { | ||
pos += utf8.EncodeRune(resBytes[pos:], r) | ||
} | ||
return resBytes | ||
} | ||
|
||
func EncodeUtf8Bytes2String(bytes []byte) string { | ||
if len(bytes) == 0 { | ||
return "" | ||
} | ||
var startPos, endPos int | ||
resRunes := make([]rune, 0, 8) | ||
for endPos <= len(bytes) { | ||
if utf8.FullRune(bytes[startPos:endPos]) { | ||
decodedRune, _ := utf8.DecodeRune(bytes[startPos:endPos]) | ||
resRunes = append(resRunes, decodedRune) | ||
startPos = endPos | ||
} | ||
endPos++ | ||
} | ||
return string(resRunes) | ||
} | ||
|
||
func DecodeBase64(bytes []byte) ([]byte, error) { | ||
dst := make([]byte, base64.StdEncoding.DecodedLen(len(bytes))) | ||
n, err := base64.StdEncoding.Decode(dst, bytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return dst[:n], nil | ||
} | ||
|
||
func EncodeBase64(bytes []byte) ([]byte, error) { | ||
dst := make([]byte, base64.StdEncoding.EncodedLen(len(bytes))) | ||
base64.StdEncoding.Encode(dst, bytes) | ||
return dst[:], nil | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New File add open source license