ssm

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package ssm provides cryptographic utilities for banking SSM operations.

Index

Constants

View Source
const DecimalizationTable string = "0123456789012345"

DecimalizationTable maps hex digits to decimal digits for PVV/CVV generation.

Variables

View Source
var BadPins []int

BadPins is the list of PIN values considered weak or easily guessable.

View Source
var ZeroIv = []byte{0, 0, 0, 0, 0, 0, 0, 0}

ZeroIv is an 8-byte zero initialization vector used for DES operations.

Functions

func AesDecrypt

func AesDecrypt(kaeyB64, ivB64, textB64 string) (string, error)

AesDecrypt decrypts a base64-encoded AES-CBC ciphertext using the given base64-encoded key and IV.

func AesEncrypt

func AesEncrypt(kaeyB64, ivB64, text string) (string, error)

AesEncrypt encrypts a plaintext string using AES-CBC with the given base64-encoded key and IV.

func Decimalize

func Decimalize(notDecimaliz string, length int, immediate bool) string

Decimalize converts hex digits to decimal digits using the decimalization table.

func DecryptDes

func DecryptDes(cipherB64, keyB64 string) (string, error)

DecryptDes decrypts a base64-encoded DES/Triple-DES ciphertext using a base64-encoded key.

func DecryptDesBothHex

func DecryptDesBothHex(cipherHex, keyHex string) (string, error)

DecryptDesBothHex decrypts a hex-encoded DES/Triple-DES ciphertext using a hex-encoded key.

func DecryptDesHex

func DecryptDesHex(cipherHex, keyB64 string) (string, error)

DecryptDesHex decrypts a hex-encoded DES/Triple-DES ciphertext using a base64-encoded key.

func DecryptRsa

func DecryptRsa(ks1 keystore.KeyStore, keyID, pass, data string) (string, error)

DecryptRsa decrypts base64-encoded RSA ciphertext using the private key from the given keystore entry.

func EncryptCvv

func EncryptCvv(tspB64, cvkB64 string) (string, error)

EncryptCvv encrypts a CVV toolstring using a two-part DES scheme with the given CVK.

func EncryptDes

func EncryptDes(textB64, keyB64 string) (string, error)

EncryptDes encrypts base64-encoded plaintext with DES/Triple-DES using a base64-encoded key.

func EncryptDesHex

func EncryptDesHex(textHex, keyB64 string) (string, error)

EncryptDesHex encrypts hex-encoded plaintext with DES/Triple-DES using a base64-encoded key.

func EncryptRsa

func EncryptRsa(ks1 keystore.KeyStore, keyID, data string) (string, error)

EncryptRsa encrypts base64-encoded data using the RSA public key from the given keystore entry.

func ExtractPanFromCard

func ExtractPanFromCard(card string) (string, error)

ExtractPanFromCard extracts the 12-digit PAN from a 16-digit card number.

func GenCvv

func GenCvv(pan, exp, service, cvkB64 string) (string, error)

GenCvv generates a CVV from the PAN, expiry date, service code, and CVK key.

func GenerateOffset

func GenerateOffset(card, pvkB64, pin string, pinlen int) (string, error)

GenerateOffset generates a PIN offset from the card, PVK, PIN, and PIN length.

func GeneratePinBlock

func GeneratePinBlock(pan, tpkB64, pin string) (string, error)

GeneratePinBlock creates an encrypted PIN block for the given PAN, TPK, and PIN.

func GeneratePvv

func GeneratePvv(card, pvkB64, pvki, pin string) (string, error)

GeneratePvv generates a PVV (PIN Verification Value) from the card, PVK, PVKI, and PIN.

func GenerateRandomPin

func GenerateRandomPin(length int) string

GenerateRandomPin generates a random PIN of the given length, avoiding weak PINs.

func Initialize

func Initialize()

Initialize seeds the random number generator for PIN generation.

func IsPinEasy

func IsPinEasy(pin int) bool

IsPinEasy reports whether the given PIN is weak or easily guessable.

func PKCS7Padding

func PKCS7Padding(ciphertext []byte) []byte

PKCS7Padding appends PKCS#7 padding bytes to the given ciphertext.

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

PKCS7UnPadding removes PKCS#7 padding bytes from the given plaintext.

func PinBlock

func PinBlock(pan, pin, tpk string) (string, error)

PinBlock encrypts a PIN block for the given PAN, PIN, and TPK key.

func RandomData

func RandomData(length int) string

RandomData generates a random base64-encoded string of the given length.

func ReadKeyStore

func ReadKeyStore(filename string, password []byte) keystore.KeyStore

ReadKeyStore loads a Java keystore from the given file using the provided password.

func SubTen

func SubTen(pin, decimalized string, length int) (string, error)

SubTen performs a digit-wise subtraction of the decimalized value from the PIN, modulo 10.

func WriteKeyStore

func WriteKeyStore(ks keystore.KeyStore, filename string, password []byte)

WriteKeyStore saves a Java keystore to the given file using the provided password.

func Zeroing

func Zeroing(buf []byte)

Zeroing overwrites the given byte slice with zeros for secure memory clearing.

Types

type DesMode

type DesMode int

DesMode identifies the DES cipher mode (ECB or CBC).

const (
	// Ecb indicates Electronic Codebook mode.
	Ecb DesMode = iota + 1
	// Cbc indicates Cipher Block Chaining mode.
	Cbc
)

type Ssm

type Ssm struct {
	Cvk  string
	Pvk  string
	Tpk  string
	Csd  string
	Pvki string
}

Ssm holds the cryptographic keys used for SSM operations including CVK, PVK, TPK, and CSD.

func Init

func Init(cvk, pvk, tpk string) (*Ssm, error)

Init creates a new Ssm instance with the given CVK, PVK, and TPK keys.

func (*Ssm) Crypt

func (s *Ssm) Crypt(data, mode string) (string, error)

Crypt encrypts or decrypts data using the Ssm's TPK key depending on the mode.

func (*Ssm) Cvv

func (s *Ssm) Cvv(pan, exp, cvvType string) (string, error)

Cvv generates a CVV (Card Verification Value) for the given PAN, expiry, and CVV type.

func (*Ssm) Cvv2Padding added in v0.16.3

func (s *Ssm) Cvv2Padding(cvv2 string) (string, error)

Cvv2Padding encrypts a CVV2 value with zero-padding using the Ssm's CSD key.

func (*Ssm) GetKey

func (s *Ssm) GetKey(id string) string

GetKey returns the value of a cryptographic key by its identifier (Cvk, Pvk, Tpk, or Csd).

func (*Ssm) Mac

func (s *Ssm) Mac(_ string) (string, error)

Mac returns a MAC (Message Authentication Code) for the given data (currently returns zeros).

func (*Ssm) Offset

func (s *Ssm) Offset(pan, pinBlock string) (string, error)

Offset generates a PIN offset from the PAN and encrypted PIN block.

func (*Ssm) PinBlock

func (s *Ssm) PinBlock(pan, pin string) (string, error)

PinBlock encrypts a PIN block for the given PAN and PIN using the Ssm's TPK key.

func (*Ssm) PinBlockDecode

func (s *Ssm) PinBlockDecode(pan, pinBlock string) (string, error)

PinBlockDecode decrypts a PIN block and extracts the plaintext PIN for the given PAN.

func (*Ssm) Pvv

func (s *Ssm) Pvv(pan, pinBlock string) (string, error)

Pvv generates a PVV (PIN Verification Value) from the PAN and encrypted PIN block.

func (*Ssm) SetKey

func (s *Ssm) SetKey(id, value string)

SetKey sets the value of a cryptographic key by its identifier (Cvk, Pvk, Tpk, or Csd).

func (*Ssm) Translate

func (s *Ssm) Translate(pan, pinBlock, tpk2nd string) (string, error)

Translate re-encrypts a PIN block from one TPK to another for key translation.

Jump to

Keyboard shortcuts

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