Skip to content

Instantly share code, notes, and snippets.

View chonlatee's full-sized avatar

Chonlatee Jumratsee chonlatee

View GitHub Profile
@chonlatee
chonlatee / .vimrc
Last active April 28, 2021 18:03
my vimrc
filetype off
set number
set relativenumber
set noswapfile
set title
set cursorline
set encoding=UTF-8
let mapleader = ","
@chonlatee
chonlatee / encrypt_aes_256_cbc.js
Last active July 4, 2019 09:43
encrypt decrypt message with nodejs with algorithm aes-256-cbc
const crypto = require('crypto')
const ALGORITHM_NAME = 'aes-256-cbc'
const ENCRYPT_KEY = 'e916e810f3858bffc8751581ca81a748'
const IV_LENGTH = 16
const NONCE_LENGTH = 4
const encryptString = (plainText) => {
const nonce = crypto.randomBytes(NONCE_LENGTH)
const iv = crypto.randomBytes(IV_LENGTH)
const cipher = crypto.createCipheriv(ALGORITHM_NAME, ENCRYPT_KEY, iv)
@chonlatee
chonlatee / main.go
Created June 25, 2019 08:48
verify signature when you send signature to other machine ( eg. server to client )
package main
import (
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
"crypto/x509"
"encoding/asn1"
"encoding/base64"
"encoding/pem"
@chonlatee
chonlatee / createkey.js
Last active June 25, 2019 08:05
sign and verify with existing private key and public key
const crypto = require('crypto')
const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'prime256v1',
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
@chonlatee
chonlatee / ecdsa.go
Last active June 25, 2019 07:59
show ecdsa private key, public key to console
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"encoding/pem"
"fmt"
)
@chonlatee
chonlatee / middle.go
Created October 5, 2018 04:45
middleware separate route in golang (use mux and negroni )
package main
import (
"fmt"
"log"
"net/http"
"github.com/urfave/negroni"
"github.com/gorilla/mux"
@chonlatee
chonlatee / .eslintrc.json
Last active October 5, 2018 04:49
simple setup .eslintrc.js for node
{
"extends": "google",
"parser": "babel-eslint",
"env": {
"es6": true,
"node": true
},
"rules": {
"semi":["error", "never"],
"quotes": ["error", "double"],
@chonlatee
chonlatee / async-await-promise-test.js
Last active February 1, 2017 08:29
just show about how to use promise and async await in same file
// need to use babel
// npm install babel-cli
// babel-node file.js
const a = (x) => {
return new Promise(resolve => {
setTimeout(() => {
resolve(x)
}, 3000)
})