adyen_encrypt

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 11 Imported by: 0

README

Adyen-Encrypt-4.5.0

Simple golang package to encrypt sensitive card data using Adyen's v4.5.0 encryption method.

Installation

go get github.com/AlienRecall/adyen-encrypt-4.5

Usage

Explained Usage:

enc, _ := adyen_encrypt.PrepareEncryptor(
	"adyen key", //required
	"adyen origin key", //optional
	"site domain", //optional
)
encryptedData, err := enc.EncryptData("card number", "card expire month", "card expire year", "card cvc")

Single field encryption:

package main

import (
	"fmt"
	"time"

	adyen_encrypt "github.com/AlienRecall/adyen-encrypt-4.5"
)

func main() {
	enc, _ := adyen_encrypt.PrepareEncryptor(
		"10001|C621C7E8267CF5A0758EC2E0530AF2B59625EFA2A26174690B401476BA5FF1AD079D881838CD625384D546DAB4E82CF1E414F1F2C7EB5420AFD9F8FF516479FD2F7EDA66572BB9C08672961C8BF528FFD0B1951B29C2332FBF301A96BA1D41DA28F39718095222C4CCFF0C0BCAECDEF944D2994D45FB81FE210090B46E5BE22CCCBAC4F413C08F90229D0E9096046BDB6745E5C549A7FEDC907646661C79A0A14ECE4EA351A07832D7228AA8D3398874D173076E475196E1DFBF35E0FDA83C047DED0156D6839D67DF1DC0D00509E8876DF209169832607B3FAE834F0DD8E78123A991E50EFD485740622FBE3EAAE6FA33BEE2DDA42465DA36D468500AF7BD01",
		"live_YCN5QJ4BXJHSTL24DUQMIHO4JQP2XDLK",
		"https://www.bstn.com",
	)
	ts := adyen_encrypt.NowTimeISO()
	data := []byte(`{"expiryMonth":"12","generationtime":"` + ts + `"}`)
	encrypted, err := enc.EncryptSingle(data)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(encrypted)
}

Card data encryption:

package main

import (
	"fmt"
	"time"

	adyen_encrypt "github.com/AlienRecall/adyen-encrypt-4.5"
)

func main() {
	enc, _ := adyen_encrypt.PrepareEncryptor(
		"10001|C621C7E8267CF5A0758EC2E0530AF2B59625EFA2A26174690B401476BA5FF1AD079D881838CD625384D546DAB4E82CF1E414F1F2C7EB5420AFD9F8FF516479FD2F7EDA66572BB9C08672961C8BF528FFD0B1951B29C2332FBF301A96BA1D41DA28F39718095222C4CCFF0C0BCAECDEF944D2994D45FB81FE210090B46E5BE22CCCBAC4F413C08F90229D0E9096046BDB6745E5C549A7FEDC907646661C79A0A14ECE4EA351A07832D7228AA8D3398874D173076E475196E1DFBF35E0FDA83C047DED0156D6839D67DF1DC0D00509E8876DF209169832607B3FAE834F0DD8E78123A991E50EFD485740622FBE3EAAE6FA33BEE2DDA42465DA36D468500AF7BD01",
		"live_YCN5QJ4BXJHSTL24DUQMIHO4JQP2XDLK",
		"https://www.bstn.com",
	)
	encryptedData, err := enc.EncryptData("4242424242424242", "12", "2023", "123")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Printf("encryptedCardNumber: %s\nencryptedExpiryMonth: %s\nencryptedExpiryYear: %s\nencryptedSecurityCode: %s\n", encryptedData.EncryptedCardNumber, encryptedData.EncryptedExpiryMonth, encryptedData.EncryptedExpiryYear, encryptedData.EncryptedSecurityCode)
}

Please note that you need to replace adyen key with the actual website's Adyen key.

Contributing

We appreciate any contributions you might make. Please feel free to submit a pull request, issue, or suggestion.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeToBase64

func EncodeToBase64(input interface{}) string

func FormatCardNumber

func FormatCardNumber(cardNumber string) string

func HexDecode

func HexDecode(e string) []byte

func NowTimeISO

func NowTimeISO() string

Types

type AdyenData

type AdyenData struct {
	EncryptedCardNumber   string `json:"encryptedCardNumber"`
	EncryptedExpiryMonth  string `json:"encryptedExpiryMonth"`
	EncryptedExpiryYear   string `json:"encryptedExpiryYear"`
	EncryptedSecurityCode string `json:"encryptedSecurityCode"`
}

type Encryptor

type Encryptor struct {
	Key       string
	OriginKey string
	Domain    string
	RsaPubKey *rsa.PublicKey
}

func NewEncryptor

func NewEncryptor(key string) *Encryptor

func PrepareEncryptor

func PrepareEncryptor(key, originkey, domain string) (enc *Encryptor, err error)

func (*Encryptor) EncryptData

func (enc *Encryptor) EncryptData(number, expMonth, expYear, cvc string) (ret *AdyenData, err error)

func (*Encryptor) EncryptSingle

func (enc *Encryptor) EncryptSingle(data []byte) (ret string, err error)

func (*Encryptor) ParseKey

func (enc *Encryptor) ParseKey() (err error)

func (*Encryptor) SetDomain

func (enc *Encryptor) SetDomain(domain string)

func (*Encryptor) SetKey

func (enc *Encryptor) SetKey(key string)

func (*Encryptor) SetOriginKey

func (enc *Encryptor) SetOriginKey(originkey string)

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Kid string `json:"kid"`
	N   string `json:"n"`
	E   string `json:"e"`
	Alg string `json:"alg"`
	Use string `json:"use"`
}

func DefaultJWK

func DefaultJWK() *JWK

func (*JWK) JWKToPem

func (jwk *JWK) JWKToPem() *rsa.PublicKey

func (*JWK) Marshal

func (jwk *JWK) Marshal() []byte

func (*JWK) ParseAdyenKey

func (jwk *JWK) ParseAdyenKey(key string) error

Jump to

Keyboard shortcuts

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