提交 7f5ea914 编写于 作者: 超越哥哥 提交者: 徐超越

issue 61仓库token和密码加密

上级 433f9a89
......@@ -16,6 +16,12 @@ limitations under the License.
package models
import (
"crypto/aes"
"crypto/cipher"
"log"
)
// GitApp ...
type GitApp struct {
Addons
......@@ -71,3 +77,31 @@ type RepoServer struct {
func (t *RepoServer) TableName() string {
return "pub_repo_server"
}
// crypto token && password
const (
AES_KEY = "12345678abcdefgh"
AES_IV = "abcdefgh12345678"
)
func AesEny(plaintext []byte) []byte {
var (
block cipher.Block
err error
)
if block, err = aes.NewCipher([]byte(AES_KEY)); err != nil {
log.Fatal(err)
}
stream := cipher.NewCTR(block, []byte(AES_IV))
stream.XORKeyStream(plaintext, plaintext)
return plaintext
}
func (repo *RepoServer) Crypto() {
plainText := []byte(repo.Token)
repo.Token = string(AesEny(plainText))
}
func (repo *RepoServer) DecryptoToken() {
repo.Token = string(AesEny([]byte(repo.Token)))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册