doubleclick

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: MIT Imports: 7 Imported by: 0

README

Doubleclick

Go PkgGoDev

This package implements the decryption of prices according to Google's OpenRTB-DoubleClick cryptography: https://developers.google.com/authorized-buyers/rtb/response-guide/decrypt-price.

Decoding a price using the examples that Google shows in their website:

icKey, ecKey, err := ParseKeys(base64.URLEncoding, []byte("arO23ykdNqUQ5LEoQ0FVmPkBd7xB5CO89PDZlSjpFxo="), []byte("skU7Ax_NL5pPAFyKdkfZjZz2-VhIN8bjj1rVFOaJ_5o="))
if err != { 
	log.Fatal(err)
}

price, err := DecryptPrice(icKey, ecKey, []byte("YWJjMTIzZGVmNDU2Z2hpN7fhCuPemC32prpWWw"))
if err != nil {
	log.Fatal(err)
}

fmt.Println(price)
// => 1900

Encoding a price using a custom initialization vector:

sampleIcKey, sampleEcKey, err = ParseKeys(base64.URLEncoding, []byte("arO23ykdNqUQ5LEoQ0FVmPkBd7xB5CO89PDZlSjpFxo="), []byte("skU7Ax_NL5pPAFyKdkfZjZz2-VhIN8bjj1rVFOaJ_5o="))
if err != nil {
	log.Fatal(err)
}

iv := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
price := uint64(1900)
encPrice, err := EncryptPrice(sampleIcKey, sampleEcKey, iv, price)
if err != nil {
	log.Fatal(err)
}

fmt.Println(string(encPrice))
// => AAECAwQFBgcICQoLDA0OD-zub_WgSbtPP9GXag

Contributing

Contributions are welcome, however this a simple project that is not bounded to change often.

Documentation

Overview

Package doubleclick implements the decryption logic for Google OpenRTB-DoubleClick cryptography.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPrice is the error returned when the price parsed
	// by DecryptPrice is not correct.
	ErrInvalidPrice = errors.New("price is invalid")
	// ErrInvalidKeys is the error returned when the keys are not
	// valid.
	ErrInvalidKeys = errors.New("invalid keys")
	// ErrInvalidIV is the error returned when the initialization
	// vector is not valid.
	ErrInvalidIV = errors.New("invalid initialization vector")
)

Functions

func DecryptPrice

func DecryptPrice(icKey, ecKey, encPrice []byte) (uint64, error)

DecryptPrice decrypts the price with google's doubleclick cryptography encoding. encPrice is an unpadded web-safe base64 encoded string according to RFC 3548. https://developers.google.com/authorized-buyers/rtb/response-guide/decrypt-price#decryption_scheme

func EncryptPrice

func EncryptPrice(icKey, ecKey, iv []byte, price uint64) ([]byte, error)

EncryptPrice encrypts the price using the provided initialization vector and keys. It encodes the price into a binary array using binary.BigEndian. This function implements the encrypting logic as defined here: https://developers.google.com/authorized-buyers/rtb/response-guide/decrypt-price#encryption-scheme

func ParseKeys

func ParseKeys(enc *base64.Encoding, ic, ec []byte) (icKey []byte, ecKey []byte, err error)

ParseKeys parses the base64 web-safe encoded keys as explained in Google's documentation: https://developers.google.com/authorized-buyers/rtb/response-guide/decrypt-price It receives a base64 encoding object since I've noticed some inconsistencies on Google's documentation and the keys they provide to Ad buyers. If you are following Google's website examples then use `base64.URLEncoding`.

Types

This section is empty.

Jump to

Keyboard shortcuts

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