crypto

package
v0.0.0-...-b8283a6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcMd5File

func CalcMd5File(filename string) (string, error)

TODO(@benqi): remove to baselib

func GenerateNonce

func GenerateNonce(size int) []byte

func GenerateStringNonce

func GenerateStringNonce(size int) string

func NewAesCBCDecrypt

func NewAesCBCDecrypt(aesKey, aesIV []byte) (cipher.BlockMode, error)

func NewAesCBCEncrypt

func NewAesCBCEncrypt(aesKey, aesIV []byte) (cipher.BlockMode, error)

func RandomBytes

func RandomBytes(size int) []byte

func RandomString

func RandomString(size int) string

func Sha1Digest

func Sha1Digest(data []byte) []byte

func Sha256Digest

func Sha256Digest(data []byte) []byte

Types

type AES256IGECryptor

type AES256IGECryptor struct {
	// contains filtered or unexported fields
}

func NewAES256IGECryptor

func NewAES256IGECryptor(aesKey, aesIV []byte) *AES256IGECryptor

func (*AES256IGECryptor) Decrypt

func (c *AES256IGECryptor) Decrypt(data []byte) ([]byte, error)

func (*AES256IGECryptor) Encrypt

func (c *AES256IGECryptor) Encrypt(data []byte) ([]byte, error)

Encrypt data长度必须是aes.BlockSize(16)的倍数,如果不是请调用者补齐

type AesCTR128Encrypt

type AesCTR128Encrypt struct {
	// contains filtered or unexported fields
}

func NewAesCTR128Encrypt

func NewAesCTR128Encrypt(key []byte, iv []byte) (*AesCTR128Encrypt, error)

key长度必须为16、24或32

func (*AesCTR128Encrypt) Encrypt

func (e *AesCTR128Encrypt) Encrypt(plaintext []byte) []byte

type AesCTR128KeySizeError

type AesCTR128KeySizeError int

func (AesCTR128KeySizeError) Error

func (k AesCTR128KeySizeError) Error() string

type AuthKey

type AuthKey struct {
	// contains filtered or unexported fields
}

func CreateAuthKey

func CreateAuthKey() *AuthKey

CreateAuthKey

## android client, pushAuthKey algo:

  • authKey if (SharedConfig.pushAuthKey == null) { SharedConfig.pushAuthKey = new byte[256]; Utilities.random.nextBytes(SharedConfig.pushAuthKey); SharedConfig.saveConfig(); }
  • calcAuthKeyId SharedConfig.pushAuthKeyId = new byte[8]; byte[] authKeyHash = Utilities.computeSHA1(SharedConfig.pushAuthKey); System.arraycopy(authKeyHash, authKeyHash.length - 8, SharedConfig.pushAuthKeyId, 0, 8);

for bots...

func NewAuthKey

func NewAuthKey(keyId int64, keyData []byte) *AuthKey

func NewClientAuthKey

func NewClientAuthKey(keyId int64, keyData []byte) *AuthKey

func (*AuthKey) AesIgeDecrypt

func (k *AuthKey) AesIgeDecrypt(msgKey, rawData []byte) ([]byte, error)

func (*AuthKey) AesIgeDecryptV1

func (k *AuthKey) AesIgeDecryptV1(msgKey, rawData []byte) ([]byte, error)

func (*AuthKey) AesIgeEncrypt

func (k *AuthKey) AesIgeEncrypt(rawData []byte) ([]byte, []byte, error)

func (*AuthKey) AesIgeEncryptV1

func (k *AuthKey) AesIgeEncryptV1(rawData []byte) ([]byte, []byte, error)

| salt <br> int64 | `session_id` <br> int64 | `message_id` <br> int64 | `seq_no` <br> int32 |`message_data_length` <br> int32 | `message_data` <br> bytes | padding12..1024 <br> bytes| |:-:|:-:|:-:|:-:|:-:|:-:|:-:|

func (*AuthKey) AuthKey

func (k *AuthKey) AuthKey() []byte

func (*AuthKey) AuthKeyId

func (k *AuthKey) AuthKeyId() int64

func (*AuthKey) Equals

func (k *AuthKey) Equals(o *AuthKey) bool

type NotificationKey

type NotificationKey struct {
	// contains filtered or unexported fields
}

func NewNotificationKey

func NewNotificationKey(keyId int64, keyData []byte) *NotificationKey

func (*NotificationKey) AesIgeDecrypt

func (k *NotificationKey) AesIgeDecrypt(msgKey, rawData []byte) ([]byte, error)

func (*NotificationKey) AesIgeEncrypt

func (k *NotificationKey) AesIgeEncrypt(rawData []byte) ([]byte, []byte, error)

func (*NotificationKey) Equals

func (k *NotificationKey) Equals(o *NotificationKey) bool

func (*NotificationKey) NotificationKey

func (k *NotificationKey) NotificationKey() []byte

func (*NotificationKey) NotificationKeyId

func (k *NotificationKey) NotificationKeyId() int64

type PasswordKdfAlgoModPow

type PasswordKdfAlgoModPow struct {
	Salt1 []byte
	Salt2 []byte
	G     int32
	P     []byte
}

type RSACryptor

type RSACryptor struct {
	// contains filtered or unexported fields
}

func NewRSACryptor

func NewRSACryptor(keyFile string) (*RSACryptor, error)

func NewRSACryptorByKeyData

func NewRSACryptorByKeyData(pkcs1PemPrivateKey []byte) (*RSACryptor, error)

func (*RSACryptor) Decrypt

func (m *RSACryptor) Decrypt(b []byte) []byte

func (*RSACryptor) Encrypt

func (m *RSACryptor) Encrypt(b []byte) []byte

type SRPUtil

type SRPUtil struct {
	*PasswordKdfAlgoModPow
	// contains filtered or unexported fields
}

func MakeSRPUtil

func MakeSRPUtil(algo *PasswordKdfAlgoModPow) *SRPUtil

func (*SRPUtil) CalcClientM

func (m *SRPUtil) CalcClientM(newSalt1, xBytes, srpB []byte) ([]byte, []byte)

func (*SRPUtil) CalcClientM2

func (m *SRPUtil) CalcClientM2(newSalt1, aBytes, ABytes, xBytes, srpB []byte) []byte

func (*SRPUtil) CalcM

func (m *SRPUtil) CalcM(newSalt1, vBytes, srpA, srpb, srpB []byte) []byte

func (*SRPUtil) CalcSRPB

func (m *SRPUtil) CalcSRPB(vBytes []byte) ([]byte, []byte)

func (*SRPUtil) CalcSRPB2

func (m *SRPUtil) CalcSRPB2(bNonce, vBytes []byte) []byte

func (*SRPUtil) CheckNewSalt1

func (m *SRPUtil) CheckNewSalt1(newSalt1 []byte) bool

func (*SRPUtil) GetV

func (m *SRPUtil) GetV(newSalt1, passwordBytes []byte) *big.Int

func (*SRPUtil) GetVBytes

func (m *SRPUtil) GetVBytes(newSalt1, passwordBytes []byte) []byte

func (*SRPUtil) GetX

func (m *SRPUtil) GetX(newSalt1, passwordBytes []byte) []byte

type SfuKey

type SfuKey struct {
	// contains filtered or unexported fields
}

func NewSfuKey

func NewSfuKey(keyId int64, keyData []byte) *SfuKey

func (*SfuKey) AesIgeDecrypt

func (k *SfuKey) AesIgeDecrypt(incoming, signaling bool, msgKey, rawData []byte) ([]byte, error)

func (*SfuKey) AesIgeEncrypt

func (k *SfuKey) AesIgeEncrypt(incoming, signaling bool, rawData []byte) ([]byte, []byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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