Skip to content

walmat/cs2-encryption

Repository files navigation

Cybersource V2 Encryption

A small (~9kB) helper library to port NodeJS WebCrypto and perform Cybersource V2 MicroForm encryption.

NPM registry NPM license

Installation

yarn add cs2-encryption --save

// or

npm i cs2-encryption -S

Card Types

import { CardTypes } from 'cs2-encryption';

console.log(CardTypes.Visa);
// => '001'

Example Usage

import { encrypt, CardData, CardTypes } from 'cs2-encryption';

// Received from `POST` to https://flex.cybersource.com/flex/v2/tokens
const context = "eyJraWQiOiJsbiIsImFsZyI...";

const data: CardData = {
  number: "4242424242424242",
  securityCode: "123",
  expirationMonth: "10",
  expirationYear: "2021",
  type: CardTypes.Visa, // see `CardTypes` declarations 
};

const encrypted = await encrypt(data, context);

console.log(encrypted);
// => eyJraWQiOiIwM3dEVnJC...

console.log(typeof encrypted);
// => string (an encrypted JWT)

Changelog

[1.0.4] - 2021-01-25

Changed

  • Fixed types
  • Fixed compilation error from WebCrypto port

[1.0.0 - 1.0.3] - 2020-11-06

Added

  • Cybersource V2 Encryption

About

Cybersource V2 MicroForm Encryption

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published