Release v2.2.0

This commit is contained in:
Santiago Lezica
2021-11-12 19:06:13 -03:00
parent 64a820d429
commit 58d843ad79
249 changed files with 73797 additions and 1145 deletions

48
vendor/github.com/fiatjaf/go-lnurl/aes.go generated vendored Normal file
View File

@@ -0,0 +1,48 @@
package lnurl
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"io"
)
func AESCipher(key, plaintext []byte) (ciphertext []byte, iv []byte, err error) {
pad := aes.BlockSize - (len(plaintext) % aes.BlockSize)
padding := make([]byte, pad)
for i := 0; i < pad; i++ {
padding[i] = byte(pad)
}
plaintext = append(plaintext, padding...)
block, err := aes.NewCipher(key)
if err != nil {
return
}
ciphertext = make([]byte, len(plaintext))
iv = make([]byte, aes.BlockSize)
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
return
}
cbc := cipher.NewCBCEncrypter(block, iv)
cbc.CryptBlocks(ciphertext, plaintext)
return
}
func AESDecipher(key, ciphertext, iv []byte) (plaintext []byte, err error) {
block, err := aes.NewCipher(key)
if err != nil {
return
}
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(ciphertext, ciphertext)
size := len(ciphertext)
pad := ciphertext[size-1]
plaintext = ciphertext[:size-int(pad)]
return plaintext, nil
}