Coder Social home page Coder Social logo

secure_random.ex's Introduction

SecureRandom.ex [travis]

SecureRandom is an elixir module loosely based on Ruby's SecureRandom. I needed urlsafe, random, base64 strings and UUID generation, so I ported over what I needed :).

This gets its random from Erlang's strong_rand_bytes/1 and is strongly based from this gist. I had to remove some things that didn't make it to Elixir 1.0, and cut the stuff that I do not currently have use for.

Will accept PR's to flesh out further.

INSTALL

Add this to your mix.exs:

defp deps do
  [{:secure_random, "~> 0.5"}]
end

Fetch this motherlover:

mix deps.get

USAGE

UUID:

SecureRandom.uuid # => "e8bc6fde-3c11-cc2e-903b-745221154d8a"

base64 string:

SecureRandom.base64(8) # => "VsifwaD2HCk="

urlsafe_base64 string:

SecureRandom.urlsafe_base64 #=> "WAut546EWdXM3O_9sJGvmQ"

AUTHOR

Brought to you by Adequate Kitchen which is a vague way saying Patrick Robertson.

LICENSE

Apache 2.0

secure_random.ex's People

Contributors

patricksrobertson avatar jimberlage avatar railsmechanic avatar lowks avatar yoavlt avatar ugisozols avatar mus0u avatar

Stargazers

 avatar Eugen Trippel avatar Louis Smit avatar Papillon6814 avatar Benjamin Leeds avatar Bünyamin Inan avatar IKEDA Hiroki avatar Masashi Yokota avatar Paul Meserve avatar  avatar Chris Erin avatar Denis Andrejew avatar  avatar Vadim Shalamov avatar Mark Holmberg avatar Sérgio Hilgert avatar Vinicius Souza avatar Gustavo Mora González avatar Aaron Cruz avatar @cdcme avatar Muhammad Tanweer avatar Gayan avatar Ryan James Spencer avatar Hoa Nguyen avatar Jozef Vaclavik avatar Thomas Citharel avatar Dwi Wahyudi avatar Sirius248 avatar Hector De Diego avatar Lily Sellers avatar John Knott avatar David Magalhães avatar  avatar Tejumola Pelumi avatar Josh avatar KeitaTakahashi avatar Nicolas Blanco avatar Ryo Hirayama avatar Zen Savona avatar TheAnh avatar Nathan Goddard avatar Arvid Kahl avatar Oleg avatar Mathew Bramson avatar Alex avatar Andrew O'Neill avatar Andrey Marchenko avatar Oliver Eidel avatar Will Ridgers avatar  avatar AkiraFukushima avatar Seb Jacobs avatar Matt Furden avatar Charleno Pires avatar John O'Gara avatar open source avatar Ronen avatar James Walker avatar Rafael Jesus avatar amitai avatar Rockwell Schrock avatar Dorian Karter avatar Austin Ziegler avatar  avatar Joshua Dotson avatar  avatar Hugh Francis avatar Alexander Merkulov avatar Anand Dhillon avatar Josh Rieken avatar Paulo Diniz avatar Nick Poorman avatar Jesse Herrick avatar Filipe Cabaço avatar Jun Lin avatar Shunsuke Wada avatar Eric Bailey avatar Sebastian Kosch avatar Sergey Korochansky avatar 啊 坤 avatar  avatar Christian Meunier avatar Alexey Poimtsev avatar  avatar Lin He avatar Robert avatar Spencer Murray avatar Elliot Larson avatar Marcin Henryk Bartkowiak avatar Peter avatar Louis Simoneau avatar Trevor Strieber avatar David Peredo avatar Sean Tan avatar Keitaroh Kobayashi avatar Christoph Grabo avatar

Watchers

 avatar James Cloos avatar

secure_random.ex's Issues

Length of returned hex string is not constant

When I execute SecureRandom.hex(12) multiple times, it returns quite often Strings with a length of 23 characters instead of 24 characters. I think this is not the expected behavior, as the Ruby counterpart returns strings with a constant size of the expected 24 characters.

iex(1)> SecureRandom.hex(12) |> String.length
24
iex(2)> SecureRandom.hex(12) |> String.length
24
iex(3)> SecureRandom.hex(12) |> String.length
24
iex(4)> SecureRandom.hex(12) |> String.length
23
iex(5)> SecureRandom.hex(12) |> String.length
24

UUID generated is not version 4

I noticed that the UUID being generated isn't following the UUID v4 schema.

This algorithm sets the version number (4 bits) as well as two reserved bits. All other bits (the remaining 122 bits) are set using a random or pseudorandom data source. Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B (e.g., f47ac10b-58cc-4372-a567-0e02b2c3d479).

For a conformant UUID v4 implementation, see the generate function in https://github.com/elixir-lang/ecto/blob/master/lib/ecto/uuid.ex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.