+6
-6
@@ -10,32 +10,32 @@ var (
|
||||
iv = []byte("12345678abcdefgh")
|
||||
)
|
||||
|
||||
func Padding(plainText []byte, blockSize int) []byte {
|
||||
func padding(plainText []byte, blockSize int) []byte {
|
||||
n := blockSize - len(plainText)%blockSize
|
||||
temp := bytes.Repeat([]byte{byte(n)}, n)
|
||||
plainText = append(plainText, temp...)
|
||||
return plainText
|
||||
}
|
||||
|
||||
func UnPadding(cipherText []byte) []byte {
|
||||
func unPadding(cipherText []byte) []byte {
|
||||
end := cipherText[len(cipherText)-1]
|
||||
cipherText = cipherText[:len(cipherText)-int(end)]
|
||||
return cipherText
|
||||
}
|
||||
|
||||
func AES_CBC_Encrypt(plainText []byte, key []byte) []byte {
|
||||
func AESCBCEncrypt(plainText []byte, key []byte) []byte {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
plainText = Padding(plainText, block.BlockSize())
|
||||
plainText = padding(plainText, block.BlockSize())
|
||||
blockMode := cipher.NewCBCEncrypter(block, iv)
|
||||
cipherText := make([]byte, len(plainText))
|
||||
blockMode.CryptBlocks(cipherText, plainText)
|
||||
return cipherText
|
||||
}
|
||||
|
||||
func AES_CBC_Decrypt(cipherText []byte, key []byte) []byte {
|
||||
func AESCBCDecrypt(cipherText []byte, key []byte) []byte {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -43,6 +43,6 @@ func AES_CBC_Decrypt(cipherText []byte, key []byte) []byte {
|
||||
plainText := make([]byte, len(cipherText))
|
||||
blockMode := cipher.NewCBCDecrypter(block, iv)
|
||||
blockMode.CryptBlocks(plainText, cipherText)
|
||||
plainText = UnPadding(plainText)
|
||||
plainText = unPadding(plainText)
|
||||
return plainText
|
||||
}
|
||||
|
||||
+4
-4
@@ -13,7 +13,7 @@ import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func RSA_Gen(bits int) {
|
||||
func RSAGen(bits int) {
|
||||
//get current path
|
||||
_, currentpath, _, _ := runtime.Caller(0)
|
||||
currentpath = filepath.Dir(currentpath)
|
||||
@@ -75,7 +75,7 @@ func RSA_Gen(bits int) {
|
||||
pem.Encode(publickeyfile, &publickeyblock)
|
||||
}
|
||||
|
||||
func RSA_Encrypt(plainText []byte, publickeypath string) []byte {
|
||||
func RSAEncrypt(plainText []byte, publickeypath string) []byte {
|
||||
//open publickeyfile
|
||||
publickeyfile, err := os.Open(publickeypath)
|
||||
if err != nil {
|
||||
@@ -110,7 +110,7 @@ func RSA_Encrypt(plainText []byte, publickeypath string) []byte {
|
||||
return cipherText
|
||||
}
|
||||
|
||||
func RSA_Decrypt(cipherText []byte) []byte {
|
||||
func RSADecrypt(cipherText []byte) []byte {
|
||||
//open privatekeyfile
|
||||
privatekeyfile, err := os.Open(config.PrivateKeyPath)
|
||||
if err != nil {
|
||||
@@ -138,7 +138,7 @@ func RSA_Decrypt(cipherText []byte) []byte {
|
||||
return plainText
|
||||
}
|
||||
|
||||
func RSA_Sign_SHA1(cipherText []byte) []byte {
|
||||
func RSASignSHA1(cipherText []byte) []byte {
|
||||
//open privatekeyfile
|
||||
privatekeyfile, err := os.Open(config.PrivateKeyPath)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user