Git Product home page Git Product logo

go-adyen-ces's Introduction

adyen order encrypt by golang

yeezy_supply adyen order encrypt

## 
https://github.com/Apercu/adyen-encrypt

## 版本
0_1_21

## 其他实现
java sdk 
https://github.com/Adyen/adyen-android/blob/master/cse/src/main/java/com/adyen/checkout/cse/internal/CardEncryptorImpl.java

go-adyen-ces's People

Contributors

gtsigner avatar

Stargazers

Ben Stahl avatar  avatar  avatar  avatar nocloutniko avatar Jeremy Morrison avatar  avatar Florrdv avatar Goga avatar Daniel Edeling avatar  avatar Vantiboolean avatar Junior avatar Matthew Wall avatar  avatar

Watchers

James Cloos avatar  avatar

go-adyen-ces's Issues

rsa 中 填写不是和js 一样的10001 ,修改为65537

err := yen.rsa.SetPublicKey(publicKey, 65537)
package adyen

import (
    "crypto/rand"
    "crypto/rsa"
    "encoding/base64"
    "encoding/hex"
    "math/big"
)

type adrsa struct {
    publicKey  *rsa.PublicKey
    privateKey *rsa.PrivateKey
}

func (r *adrsa) SetPublicKey(pubHex string, e int) error {
    k := &rsa.PublicKey{}
    dec, err := hex.DecodeString(pubHex)
    if err != nil {
        return err
    }
    k.N = new(big.Int).SetBytes(dec)
    k.E = e
    r.publicKey = k
    return nil
}

func (r *adrsa) Encrypt(str string, encoding string) (string, error) {
    bytes := []byte(str)
    res, err := rsa.EncryptPKCS1v15(rand.Reader, r.publicKey, bytes)
    if err != nil {
        return "", err
    }
    if encoding == "base64" {
        return base64.StdEncoding.EncodeToString(res), nil
    }
    return hex.EncodeToString(res), nil
}

func (r *adrsa) Encrypt2(bytes []byte, encoding string) (string, error) {
    res, err := rsa.EncryptPKCS1v15(rand.Reader, r.publicKey, bytes)
    if err != nil {
        return "", err
    }
    if encoding == "base64" {
        return base64.StdEncoding.EncodeToString(res), nil
    }
    return hex.EncodeToString(res), nil
}
func NewRsa() *adrsa {
    rs := &adrsa{}
    return rs
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.