MCPcopy Create free account
hub / github.com/Preloading/TwitterAPIBridge / Decrypt

Function Decrypt

cryption/authcrypt.go:53–85  ·  view source on GitHub ↗

Decrypt decrypts the given base64 encoded ciphertext using AES-GCM with the provided base64 encoded key and returns the plaintext

(base64Ciphertext, base64Key string)

Source from the content-addressed store, hash-verified

51
52// Decrypt decrypts the given base64 encoded ciphertext using AES-GCM with the provided base64 encoded key and returns the plaintext
53func Decrypt(base64Ciphertext, base64Key string) (string, error) {
54 key, err := base64.StdEncoding.DecodeString(base64Key)
55 if err != nil {
56 return "", err
57 }
58
59 ciphertext, err := base64.StdEncoding.DecodeString(base64Ciphertext)
60 if err != nil {
61 return "", err
62 }
63
64 block, err := aes.NewCipher(key)
65 if err != nil {
66 return "", err
67 }
68
69 gcm, err := cipher.NewGCM(block)
70 if err != nil {
71 return "", err
72 }
73
74 if len(ciphertext) < gcm.NonceSize() {
75 return "", errors.New("ciphertext too short")
76 }
77
78 nonce, ciphertext := ciphertext[:gcm.NonceSize()], ciphertext[gcm.NonceSize():]
79 plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
80 if err != nil {
81 return "", err
82 }
83
84 return string(plaintext), nil
85}
86
87// it took me an embarrising long time to learn that the jwt tokens encode the expiration time inside of them
88func GetJWTTokenExpirationUnix(token string) (*float64, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected