impl entities except for PATCH

This commit is contained in:
breel
2020-08-08 12:01:49 -06:00
parent 1655a9b83a
commit f88ade0d73
25 changed files with 195 additions and 33 deletions

44
.view/.aes/main.go Normal file
View File

@@ -0,0 +1,44 @@
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"errors"
"log"
"os"
"strings"
)
func main() {
key := os.Args[1]
value := os.Args[2]
log.Println(aesDec(key, value))
}
func aesDec(key, payload string) (string, error) {
if len(key) == 0 {
return "", errors.New("key required")
}
key = strings.Repeat(key, 32)[:32]
ciphertext, err := base64.StdEncoding.DecodeString(payload)
if err != nil {
return "", err
}
block, err := aes.NewCipher([]byte(key))
if err != nil {
return "", err
}
gcm, err := cipher.NewGCM(block)
if err != nil {
return "", err
}
log.Println(gcm.NonceSize())
if len(ciphertext) < gcm.NonceSize() {
return "", errors.New("short ciphertext")
}
b, err := gcm.Open(nil, ciphertext[:gcm.NonceSize()], ciphertext[gcm.NonceSize():], nil)
return string(b), err
}