Documentation ¶
Index ¶
- Constants
- Variables
- func AES(keySize AESKeySize) ([]byte, error)
- func AESKeySet(preset AESKeyPreset) (*jwkcore.AESKeySet, error)
- func EC(curve elliptic.Curve) (*ecdsa.PrivateKey, error)
- func ED25519() (ed25519.PrivateKey, ed25519.PublicKey, error)
- func HMAC(size int) ([]byte, error)
- func IV(ivSize IVSize) ([]byte, error)
- func RSA(size int) (*rsa.PrivateKey, error)
- func X25519() (*ecdh.PrivateKey, error)
- type AESKeyPreset
- type AESKeySize
- type IVSize
Constants ¶
View Source
const ( // H256KeySize is the recommended key size for HMAC 256 keys. // // If the key is more than 64 bytes long, it is hashed (using SHA-384) to derive a 32-byte key. // // https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.hmacsha256.-ctor?view=net-9.0 H256KeySize = 64 // H384KeySize is the recommended key size for HMAC 384 keys. // // If the key is more than 128 bytes long, it is hashed (using SHA-384) to derive a 48-byte key. // // https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.hmacsha384.-ctor?view=net-9.0 H384KeySize = 128 // H512KeySize is the recommended key size for HMAC 512 keys. // // If the key is more than 128 bytes long, it is hashed (using SHA-384) to derive a 64-byte key. // // https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.hmacsha512.-ctor?view=net-9.0 H512KeySize = 128 )
View Source
const ( // RS256KeySize is the recommended key size for RSA 256 keys. // // The signature size (in bytes, before re-encoding as text) is the key size (in bit), divided by 8 and rounded up // to the next integer. // // ⌈2048/8⌉=256 bytes. // // https://crypto.stackexchange.com/a/95882 RS256KeySize = 2048 // RS384KeySize is the recommended key size for RSA 384 keys. // // The signature size (in bytes, before re-encoding as text) is the key size (in bit), divided by 8 and rounded up // to the next integer. // // ⌈3072/8⌉=384 bytes. // // https://crypto.stackexchange.com/a/95882 RS384KeySize = 3072 // RS512KeySize is the recommended key size for RSA 512 keys. // // The signature size (in bytes, before re-encoding as text) is the key size (in bit), divided by 8 and rounded up // to the next integer. // // ⌈4096/8⌉=512 bytes. // // https://crypto.stackexchange.com/a/95882 RS512KeySize = 4096 )
Variables ¶
View Source
var ( A128GCMKeyPreset = AESKeyPreset{ KeySize: AESKeySize128, IVSize: IVSize96, } A192GCMKeyPreset = AESKeyPreset{ KeySize: AESKeySize192, IVSize: IVSize96, } A256GCMKeyPreset = AESKeyPreset{ KeySize: AESKeySize256, IVSize: IVSize96, } A128CBCKeyPreset = AESKeyPreset{ KeySize: AESKeySize256, IVSize: IVSize128, } A192CBCKeyPreset = AESKeyPreset{ KeySize: AESKeySize384, IVSize: IVSize128, } A256CBCKeyPreset = AESKeyPreset{ KeySize: AESKeySize512, IVSize: IVSize128, } )
Functions ¶
func AES ¶
func AES(keySize AESKeySize) ([]byte, error)
AES creates a new random key that can be used for symmetric encryption.
func AESKeySet ¶
func AESKeySet(preset AESKeyPreset) (*jwkcore.AESKeySet, error)
AESKeySet creates a new random key and IV that can be used for symmetric encryption.
func EC ¶
func EC(curve elliptic.Curve) (*ecdsa.PrivateKey, error)
EC generates a new ECDSA private key of the given curve.
The curve must be one of the following: - elliptic.P256() - elliptic.P384() - elliptic.P521()
func ED25519 ¶
func ED25519() (ed25519.PrivateKey, ed25519.PublicKey, error)
ED25519 generates a new EdDSA key pair.
func HMAC ¶
HMAC generates a cryptographically secure random byte slice of the given size. The generated key can be used to sign a token using HMAC.
You can use the recommended default constants as the size parameter.
- H256KeySize
- H384KeySize
- H512KeySize
Types ¶
type AESKeyPreset ¶
type AESKeyPreset struct { // KeySize is the size of the content encryption key to generate. KeySize AESKeySize // IVSize is the size of the initialization vector to generate. IVSize IVSize }
AESKeyPreset is a set of parameters that can be used to generate a full AESKeySet.
type AESKeySize ¶
type AESKeySize int
const ( AESKeySize128 AESKeySize = 16 AESKeySize192 AESKeySize = 24 AESKeySize256 AESKeySize = 32 AESKeySize384 AESKeySize = 48 AESKeySize512 AESKeySize = 64 )
Click to show internal directories.
Click to hide internal directories.