comm

package
v0.0.0-...-4345fab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

=====This is a GO API file for parse server-client transport pkg in SGame Framework===== * more info:https://github.com/nmsoccer/sgame ======================================================================================= NET-PKG Tag + Len + Value (1B) (1|2|4B) (...) |<- head ->| |<- data ->|

*Tag: 1Byte **Tag: 0 0 0 0 0 | 0 0 0 high-5bits:option , low-3bits: Bytes of len

*Len: 1 or 2 or 4Byte **len [1,0xFF] :1Byte **len (0xFF , 0xFFFF] :2Byte **len (0xFFFF , 0xFFFFFFFF]: 4Byte

Index

Constants

View Source
const (
	ENCRY_DES_KEY_LEN = 8
	ENCRY_AES_KEY_LEN = 16

	NET_ENCRYPT_NONE        int8 = 0
	NET_ENCRYPT_DES_ECB     int8 = 1 //desc-ecb
	NET_ENCRYPT_AES_CBC_128 int8 = 2 //aes-cbc-128
	NET_ENCRYPT_RSA         int8 = 3 //rsa + des or aes
)
View Source
const (
	TAG_LEN = 1
	INT_MAX = 0x7FFFFFF0
	//pkg option
	PKG_OP_NORMAL   = 0  //normal pkg
	PKG_OP_ECHO     = 1  //echo client <-> tcp-serv
	PKG_OP_VALID    = 2  //valid connection client-->server[validate] server-->client[enc_key if enc enable]
	PKG_OP_RSA_NEGO = 3  //encrypt by rsa_pub_key to negotiate des key client-->server[encrypted key] server-->client[result]
	PKG_OP_MAX      = 32 //max option value

	//VALID_KEY
	CONN_VALID_KEY = "c#s..x*.39&suomeI./().32&show+me_tHe_m0ney$"
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(block cipher.Block, cryted []byte, key []byte) ([]byte, error)

AES-CBC key must 16bits if @block != nil use it , or new block

func AesEncrypt

func AesEncrypt(block cipher.Block, orig []byte, key []byte) ([]byte, error)

******************AES********************** AES-CBC key must 16bits if @block != nil use it , or new block

func DesDecrypt

func DesDecrypt(block cipher.Block, src []byte, key []byte) ([]byte, error)

if @block != nil use it , or new block

func DesEncrypt

func DesEncrypt(block cipher.Block, src []byte, key []byte) ([]byte, error)

******************DES********************** DES-ECB key must 8bits if @block != nil use it , or new block

func GetPkgLen

func GetPkgLen(data_len int) int

predict pkg-len according to data_len -1:if data_len illegal else pkg-len

func PackPkg

func PackPkg(pkg_buff []byte, pkg_data []byte, pkg_option uint8) int

Pack pkg_data to pkg. @pkg_option: ==0 normal pkg. > 0 PKG_OP_XX means special pkg to server @return: -1:failed -2:buff_len not enough >0:success(pkg_len)

func Pkcs5Padding

func Pkcs5Padding(ciphertext []byte, blockSize int) []byte

pad & unpad

func Pkcs5UnPadding

func Pkcs5UnPadding(origData []byte) []byte

func PkgOption

func PkgOption(tag uint8) uint8

Get pkg-option @return:PKG_OP_XX

func RsaDecrypt

func RsaDecrypt(ciphertext []byte, privateKey []byte) ([]byte, error)

私钥解密 PKCS1

func RsaDecrypt8

func RsaDecrypt8(ciphertext []byte, privateKey []byte) ([]byte, error)

解密 PKCS8(java may use it)

func RsaEncrypt

func RsaEncrypt(origData []byte, publicKey []byte) ([]byte, error)

******************RSA********************** 公钥加密

func UnPackPkg

func UnPackPkg(raw []byte) (uint8, []byte, int)

UnPackPkg from raw data @return:(pkg_tag , pkg_data , pkg_len) @pkg_tag 0xFF:error , 0:data not ready , else:success and valid tag of pkg

if tag is valid then will return valid pkg_data and pkg_len

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL