TravisBuildStatus GoDoc GoReportCard codecov
[TOC]
install
go get -u -v github.com/sinlov/fastEncryptDecode
in go mod project
# see full version $ go list -m -versions github.com/sinlov/fastEncryptDecode # use as $ echo "go mod edit -require=$(go list -m -versions github.com/sinlov/fastEncryptDecode | awk '{print 1ドル "@" $NF}')" $ echo "go mod vendor"
import ( "github.com/sinlov/fastEncryptDecode" )
// Byte arrary to String pStr := ByteArr2Str(deAES) // byte arrary to hex string hexString := ByteArr2HexStr(hexStr) // byte arrary to hex string arrary hexStrArr := ByteArr2HexStrArr(hexStr) for _, s := range hexStrArr { fmt.Println("ByteArr2HexStrArr: ", s) } // hex string to byte arrary byteArr, err := HexStr2ByteArr(hexString)
// byte to uint8 b := 0x13 i := uint8(b) // uint8 to byte var i uint8 i = 3 b := byte(i) // byte[] to uint 16 32 64 use | package encoding/binary uNumber := binary.BigEndian.Uint16(data[12 : 36])
- You must check len at []byte for support
- more info see func TestByteAndUint at method
TestByteAndUint
bStr := "转换前的中文" enUnicode := Utf82Unicode(bStr) enUtf8 := Unicode2Utf8(enUnicode) fmt.Println(bStr, enUnicode, enUtf8)
- MD5Hash
str4MD5 := "0987654321" enMD5 := MD5hash([]byte(str4MD5)) // if string enMD5 := String2MD5(str4MD5)
- MD5 Verify
verifyTrue := MD5Verify(str4MD5, "25d55ad283aa400af464c761d713c07a")
for encode by Base64 Safe encode
fmt.Println("base64UrlSafe: ", Base64UrlSafeEncode(enAES))
this package use CBC pkcs7 padding length 128byte or string size 16
- string
str4AES := "qwertasdgzxcv" enAES, err := fastEncryptDecode.AES_CBC_PKCS7_Encrypt(str4AES, AES_KEY) deASE, err := fastEncryptDecode.AES_CBC_PKCS7_Decrypt(enAES, AES_KEY)
- []byte
str4AES := "qwer1234aisudfhsfhsidhaskfahfahkufahukfh" enAES, err := fastEncryptDecode.AES_CBC_PKCS7_EncryptByte([]byte(str4AES), []byte(AES_KEY)) deAES, err := fastEncryptDecode.AES_CBC_PKCS7_DecryptByte(enAES, []byte(AES_KEY))
this package use ECB pkcs5 padding length 128byte or string size 16
- string
str4AES := "qwer1234adasdadadasdadaasadashkafhkfhkf" enAES, err := AES_ECB_PKCS5_Encrypt(str4AES, AES_KEY) deASE, err := AES_ECB_PKCS5_Decrypt(enAES, AES_KEY)
- []byte
str4AES := "qwer1234aisudfhsfhsidhaskfahfahkufahukfhkadadasdadadasdadaasadashkafhkfhkf" enAES, err := AES_ECB_PKCS5_EncryptByte([]byte(str4AES), []byte(AES_KEY)) deAES, err := AES_ECB_PKCS5_DecryptByte(enAES, []byte(AES_KEY))
#License
Copyright 2016 sinlovgm@gmail.com
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.