Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeBase64(data string) ([]byte, error)
- func Decrypt(ciphertext []byte, key []byte) ([]byte, error)
- func DecryptHybrid(encryptedData []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func DecryptRSA(ciphertext []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func DecryptSymmetric(ciphertext []byte, key []byte) ([]byte, error)
- func DeserializeRSAPrivateKey(privateKeyPEM []byte) (*rsa.PrivateKey, error)
- func DeserializeRSAPublicKey(publicKeyPEM []byte) (*rsa.PublicKey, error)
- func EncodeBase64(data []byte) string
- func Encrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)
- func EncryptHybrid(plaintext []byte, publicKey *rsa.PublicKey) ([]byte, error)
- func EncryptRSA(plaintext []byte, publicKey *rsa.PublicKey) ([]byte, error)
- func EncryptSymmetric(plaintext []byte, key []byte, iv []byte) ([]byte, error)
- func GenerateRSAKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func SerializeRSAPrivateKey(privateKey *rsa.PrivateKey) []byte
- func SerializeRSAPublicKey(publicKey *rsa.PublicKey) []byte
- func VerifyHash(hashedPassword, password []byte) error
- type Algorithm
- type HashedPassword
- type JWT
- type JwtClaims
Constants ¶
const ( DefaultCost = 10 MinCost = 4 MaxCost = 31 SaltLength = 16 HashLength = 32 HashVersion = "v1" )
Variables ¶
Functions ¶
func DecodeBase64 ¶
func DecryptHybrid ¶
func DecryptHybrid(encryptedData []byte, privateKey *rsa.PrivateKey) ([]byte, error)
DecryptHybrid decrypts data using hybrid encryption (AES + RSA).
func DecryptRSA ¶
func DecryptRSA(ciphertext []byte, privateKey *rsa.PrivateKey) ([]byte, error)
DecryptRSA decrypts data using RSA-OAEP.
func DecryptSymmetric ¶
DecryptSymmetric decrypts data using AES-256-GCM with a user-provided key. The IV is extracted from the beginning of the ciphertext.
func DeserializeRSAPrivateKey ¶
func DeserializeRSAPrivateKey(privateKeyPEM []byte) (*rsa.PrivateKey, error)
DeserializeRSAPrivateKey deserializes an RSA private key from PEM format.
func DeserializeRSAPublicKey ¶
DeserializeRSAPublicKey deserializes an RSA public key from PEM format.
func EncodeBase64 ¶
func EncryptHybrid ¶
EncryptHybrid encrypts data using hybrid encryption (AES + RSA). The AES key is encrypted with RSA, and the IV is stored alongside the ciphertext.
func EncryptRSA ¶
EncryptRSA encrypts data using RSA-OAEP.
func EncryptSymmetric ¶
EncryptSymmetric encrypts data using AES-256-GCM with a user-provided key and IV. If no IV is provided, a random one is generated.
func GenerateRSAKeyPair ¶
GenerateRSAKeyPair generates a new RSA key pair.
func SerializeRSAPrivateKey ¶
func SerializeRSAPrivateKey(privateKey *rsa.PrivateKey) []byte
SerializeRSAPrivateKey serializes an RSA private key to PEM format.
func SerializeRSAPublicKey ¶
SerializeRSAPublicKey serializes an RSA public key to PEM format.
func VerifyHash ¶
Types ¶
type HashedPassword ¶
func Hash ¶
func Hash(password []byte) (*HashedPassword, error)
func HashWithCost ¶
func HashWithCost(password []byte, cost int) (*HashedPassword, error)