Giter Site home page Giter Site logo

aes's Introduction

Aes

a golang library to use aes encrypt easier.

Install

go get github.com/hanson/aes

Document

import

import github.com/hanson/aes

CBC

orig := "hello world"
key := "0123456789012345"

encryptCode := aes.AesEncryptCBC(orig, key)
fmt.Println("encrypt:" , encryptCode)
decryptCode := aes.AesDecryptCBC(encryptCode, key)
fmt.Println("decrypt:", decryptCode)

CFB

source := "hello world"
fmt.Println("origin:", source)
key := "ABCDEFGHIJKLMNO1" // 16 byte

encryptCode, err := aes.AesEncryptCFB([]byte(source), []byte(key))
if err != nil {
    log.Printf("err:%v", err)
    return
}

fmt.Println("encryptCode:", hex.EncodeToString(encryptCode))

decryptCode, err := aes.AesDecryptCFB(encryptCode, []byte(key))
if err != nil {
    log.Printf("err:%v", err)
    return
}

fmt.Println("decryptCode:", string(decryptCode))

CTR

source := "hello world"
fmt.Println("origin:", source)

key := "1443flfsaWfdasds"
encryptCode, err := aes.AesCryptCTR([]byte(source), []byte(key))
if err != nil {
    log.Printf("err:%v", err)
    return
}

fmt.Println("encryptCode:", string(encryptCode))

decryptCode, err := aes.AesCryptCTR(encryptCode, []byte(key))
if err != nil {
    log.Printf("err:%v", err)
    return
}

fmt.Println("decryptCode:", string(decryptCode))

ECB

source := "hello world"
fmt.Println("origin:", source)

//16 byte
key := "1443flfsaWfdas"
encryptCode := aes.AesEncryptECB([]byte(source), []byte(key))
fmt.Println("encryptCode:", string(encryptCode))

decryptCode := aes.AesDecryptECB(encryptCode, []byte(key))

fmt.Println("decryptCode:", string(decryptCode))

OFB

source := "hello world"
fmt.Println("origin:", source)
key := "1111111111111111" //16byte or 32byte

encryptCode, err := aes.AesEncryptOFB([]byte(source), []byte(key))
if err != nil {
    log.Printf("err:%v", err)
    return
}

fmt.Println("encryptCode:", hex.EncodeToString(encryptCode))

decryptCode, err := aes.AesDecryptOFB(encryptCode, []byte(key))
if err != nil {
    log.Printf("err:%v", err)
    return
}

fmt.Println("decryptCode:", string(decryptCode))

aes's People

Contributors

hanson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.