Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64 is not privacy #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions posts/2015-02-25-my-favorite-activesupport-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,26 @@ You can use it to generate and verify signed messages

```ruby
@verifier = ActiveSupport::MessageVerifier.new('s3Krit', serializer: JSON)
@verifier.generate("private message")
#=> "InByaXZhdGUgbWVzc2FnZSI=--43fc83190b28daf8df04c0b86ff2976931a6dcd2"
@verifier.verify("InByaXZhdGUgbWVzc2FnZSI=--43fc83190b28daf8df04c0b86ff2976931a6dcd2")
#=> "private message"

@verifier.generate("a" => "private message")
#=> "eyJhIjoicHJpdmF0ZSBtZXNzYWdlIn0=--b253af3e77622f743cf6804c870f4a95cbbd6f00"
@verifier.verify("eyJhIjoicHJpdmF0ZSBtZXNzYWdlIn0=--b253af3e77622f743cf6804c870f4a95cbbd6f00")
=> {"a"=>"private message"}
@verifier.generate("signed message")
#=> "InNpZ25lZCBtZXNzYWdlIg==--e31182c43a7c13fc8d9affe8c0ed5503f79cc861"
@verifier.verify("InNpZ25lZCBtZXNzYWdlIg==--e31182c43a7c13fc8d9affe8c0ed5503f79cc861")
#=> "signed message"

@verifier.generate("a" => "signed message")
#=> "eyJhIjoic2lnbmVkIG1lc3NhZ2UifQ==--f41b7c9e79e26e528975ee3630f2ad5b8b1267d9"
@verifier.verify("eyJhIjoic2lnbmVkIG1lc3NhZ2UifQ==--f41b7c9e79e26e528975ee3630f2ad5b8b1267d9")
=> {"a"=>"signed message"}
```

Mostly obvious: it's just a signed message, not an encrypted one. You can easily look up the data after it's decoded with Base64:

```
Base64.strict_decode64("InNpZ25lZCBtZXNzYWdlIg==--e31182c43a7c13fc8d9affe8c0ed5503f79cc861".split("--").first)
#=> "\"signed message\""
```

## Summary

That's it. You can browse entire ActiveSupport codebase quickly and easily at [github](https://github.com/rails/rails/tree/master/activesupport/lib/active_support)

If you liked it, you may also enjoy [Hidden features of Ruby you may not know about](/2014/07/hidden-features-of-ruby-you-may-dont-know-about/)
If you liked it, you may also enjoy [Hidden features of Ruby you may not know about](/2014/07/hidden-features-of-ruby-you-may-dont-know-about/)