cryptox

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package cryptox holds the cryptographic primitives the Iranian PSPs ask for: 3DES-ECB signatures (Sadad), AES-CBC plus RSA envelopes (IranKish) and RSA signatures over the request body (Pasargad).

Everything is built on the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCEncrypt

func AESCBCEncrypt(key, iv, data []byte) ([]byte, error)

AESCBCEncrypt encrypts data with AES-CBC and PKCS#7 padding.

func EncryptPKCS1v15

func EncryptPKCS1v15(pub *rsa.PublicKey, data []byte) ([]byte, error)

EncryptPKCS1v15 encrypts data with the given RSA public key.

func PKCS7Pad

func PKCS7Pad(data []byte, blockSize int) []byte

PKCS7Pad appends PKCS#7 padding so the data fills whole blocks.

func ParseRSAPrivateKey

func ParseRSAPrivateKey(key string) (*rsa.PrivateKey, error)

ParseRSAPrivateKey accepts a PEM encoded PKCS#1 or PKCS#8 private key, the bare base64 body of one, or a .NET style <RSAKeyValue> XML key, which is the format Pasargad still distributes.

func ParseRSAPublicKey

func ParseRSAPublicKey(key string) (*rsa.PublicKey, error)

ParseRSAPublicKey accepts a PEM encoded PKIX or PKCS#1 public key, or the bare base64 body of one, and returns the RSA key.

func RandomBytes

func RandomBytes(n int) ([]byte, error)

RandomBytes returns n cryptographically secure random bytes.

func SHA256Sum

func SHA256Sum(data []byte) []byte

SHA256Sum returns the SHA-256 digest of data.

func SignPKCS1v15SHA1

func SignPKCS1v15SHA1(priv *rsa.PrivateKey, data []byte) (string, error)

SignPKCS1v15SHA1 signs data with RSASSA-PKCS1-v1_5 over SHA-1 and returns the base64 signature. Pasargad's "Sign" header uses this legacy combination.

func SignPKCS1v15SHA256

func SignPKCS1v15SHA256(priv *rsa.PrivateKey, data []byte) (string, error)

SignPKCS1v15SHA256 signs data with RSASSA-PKCS1-v1_5 over SHA-256 and returns the base64 signature.

func TripleDESEncryptECB

func TripleDESEncryptECB(data []byte, keyBase64 string) (string, error)

TripleDESEncryptECB encrypts data with 3DES in ECB mode and PKCS#7 padding, then base64-encodes the result. The key itself is given base64 encoded, which is how Sadad hands out terminal keys.

Types

This section is empty.

Jump to

Keyboard shortcuts

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