rskey ships two importable Go packages for programmatic use. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/rstudio/rskey/llms.txt
Use this file to discover all available pages before exploring further.
crypt package handles key generation and encryption for Connect and Package Manager. The workbench package handles the compatible-but-distinct format used by Posit Workbench. Both packages are versioned alongside the rskey CLI under strict semantic versioning.
Import paths
github.com/rstudio/rskey (see go.mod). Add it to your project with:
Package crypt
Constants and errors
KeyLength is the fixed length of a Key in bytes. The encoded (hex) form on disk is 1024 characters.
ErrFIPS is returned by encryptSecretbox and decryptSecretbox when the package is compiled with -tags fips. It surfaces through any call to Encrypt, EncryptBytes, or Decrypt that would otherwise use NaCl.
FIPSMode is a compile-time constant. It is false in standard builds (nacl.go) and true in FIPS builds (fips.go). Inspect this value at runtime to determine which encryption path will be taken by Encrypt and EncryptBytes.
Key type
Key is a securely-generated, opaque 512-byte array. All encryption and decryption methods are defined on *Key.
Constructors
crypto/rand. As of Go 1.24, rand.Read aborts rather than returning an error, so this function never returns a non-nil error despite its signature.
ErrInvalidKeyLength if the decoded length is not exactly 512 bytes.
io.Reader and delegates to NewKeyFromBytes. Useful for reading key files directly:
Serialization
Encryption
EncryptBytes([]byte(s)).
FIPSMode.
FIPSMode build tag. Equivalent to EncryptBytesFIPS([]byte(s)). Never returns an error.
Decryption
0x01 → NaCl Secretbox (versioned), 0x02 → AES-256-GCM, anything else → NaCl Secretbox (legacy unversioned). Equivalent to string(DecryptBytes(s)).
ErrPayLoadTooShort if the payload is too short, ErrFailedToDecrypt if decryption fails, or ErrFIPS if the payload requires NaCl and the build is in FIPS mode.
Key identification
Package workbench
Errors
Theworkbench package reuses crypt.ErrInvalidKeyLength, crypt.ErrPayLoadTooShort, and crypt.ErrFailedToDecrypt. It adds one additional error:
Key type
Key holds the rotated key bytes and a pre-computed CRC32 checksum string. The checksum is computed over the raw (pre-rotation) input bytes.
Constructors
minKeyLength); returns crypt.ErrInvalidKeyLength otherwise. The checksum is computed before rotation.
io.Reader and delegates to NewKeyFromBytes.
Encryption and decryption
hash8 + base64(iv[32] + ciphertext) + hash8 where hash8 is the 8-character CRC32 hex string. PKCS#7 padding is applied automatically.
ErrMissingChecksum if the two checksums differ, crypt.ErrFailedToDecrypt if the checksum does not match the key, or crypt.ErrPayLoadTooShort if the payload is too short.
Key identification
rstudio-server encrypt-password and is embedded in every Workbench ciphertext.
Usage example
FIPS build tag
To enforce FIPS mode at compile time, build with thefips tag:
crypt.FIPSModeistruecrypt.Encryptandcrypt.EncryptBytesalways use AES-256-GCM- Any call path that reaches
encryptSecretboxordecryptSecretboxreturnscrypt.ErrFIPS crypt.DecryptreturnsErrFIPSif the ciphertext version byte (0x01or unversioned) indicates NaCl
workbench package is unaffected by the fips build tag; it always uses AES-128-CBC.
rskey and its packages follow strict semantic versioning. The Go module path is github.com/rstudio/rskey. Pin to a specific version in production to avoid unexpected API changes.