Affichage des articles dont le libellé est cookie. Afficher tous les articles
Affichage des articles dont le libellé est cookie. Afficher tous les articles

jeudi 5 mai 2022

Generating a cookie secret

Generating a cookie secret 

required step for a lot of web-based use-case when a cookie must be stored on the client side, for example with oauth2-proxy to set-up remote authentication.



  • docker / python 

docker run -ti --rm python:3-alpine python -c 'import secrets,base64; print(base64.b64encode(base64.b64encode(secrets.token_bytes(16))));'



Followings solutions are from : https://oauth2-proxy.github.io/oauth2-proxy/docs/configuration/overview (v7.2.x)

  • Python

python -c 'import os,base64; print(base64.urlsafe_b64encode(os.urandom(32)).decode())'

  • Bash

dd if=/dev/urandom bs=32 count=1 2>/dev/null | base64 | tr -d -- '\n' | tr -- '+/' '-_'; echo

  • Open SSL

openssl rand -base64 32 | tr -- '+/' '-_'

  • PowerShell

# Add System.Web assembly to session, just in case
Add-Type -AssemblyName System.Web
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes([System.Web.Security.Membership]::GeneratePassword(32,4))).Replace("+","-").Replace("/","_")

  • Terraform

# Valid 32 Byte Base64 URL encoding set that will decode to 24 []byte AES-192 secret
resource "random_password" "cookie_secret" {
length = 32
override_special = "-_"
}