Skip to content

Instantly share code, notes, and snippets.

@aereal
Created Jul 2, 2020
Embed
What would you like to do?
#!/usr/bin/env ruby
require 'openssl'
require 'jwe'
require 'jwt'
require 'json'
private_key = OpenSSL::PKey::RSA.new(File.read('/Users/aereal/devel/src/github.com/aereal/playground-jwt/internal/key/test-private.pem'))
payload = { name: 'aereal' }
results = []
10.times do |i|
sleep 1 if i.even?
token = JWT.encode(payload, private_key, 'RS512')
encrypted = JWE.encrypt(token, private_key)
results.push({signed: token, encrypted: encrypted})
end
results.each_cons(2).with_index(1) do |(prev, current), i|
unless prev[:signed] == current[:signed]
warn "! ##{i} signed token mismatched: previous:#{prev[:signed]} current:#{current[:signed]}"
end
unless prev[:encrypted] == current[:encrypted]
warn "! ##{i} encrypted token mismatched: previous:#{prev[:encrypted]} current:#{current[:encrypted]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment