-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.rb
executable file
·33 lines (24 loc) · 1.23 KB
/
decrypt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base, session_key)
cookie = CGI::unescape(cookie)
salt = 'authenticated encrypted cookie'
encrypted_cookie_cipher = 'aes-256-gcm'
serializer = ActiveSupport::MessageEncryptor::NullSerializer
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
key_len = ActiveSupport::MessageEncryptor.key_len(encrypted_cookie_cipher)
secret = key_generator.generate_key(salt, key_len)
encryptor = ActiveSupport::MessageEncryptor.new(secret, cipher: encrypted_cookie_cipher, serializer: serializer)
encryptor.decrypt_and_verify(cookie, purpose: "cookie.#{session_key}")
end
puts "Получаем сессию в Rails 6/7"
puts "(для других версий рельс может не подойти, гуглите отдельный скрипт)"
puts "Вставьте куку, которую надо расшифровать:"
cookie = gets.chomp
puts "Вставьте ключ"
secret_key_base = gets.chomp
puts "Как называется ключ сессии"
session_key = gets.chomp
result = verify_and_decrypt_session_cookie(cookie, secret_key_base, session_key)
puts result.inspect