Simple Encryption in Ruby without external gems

前端 未结 9 927
庸人自扰
庸人自扰 2020-12-08 07:43

I need a simple encryption for some text strings. I want to create coupon codes and make them look cool so subsequently created code should look very different. (And besides

相关标签:
9条回答
  • 2020-12-08 08:20

    You can check all different ways of encryption/decryption using ruby in this gist: https://gist.github.com/iufuenza/183a45c601a5c157a5372c5f1cfb9e3e

    If you don't want to use a gem, I would totally recommend Openssl as the most secure which is also very easy to implement as it has very good Ruby support.

    0 讨论(0)
  • 2020-12-08 08:23

    I know that you are looking for a no-gem encryption, but still want to offer to those who are here and don't worry about using external gems. Try glogin (I'm the author):

    require 'glogin/codec'
    codec = GLogin:Codec.new('the secret')
    encrypted = codec.encrypt('Hello, world!')
    decrypted = codec.decrypt(encrypted)
    

    It's based on OpenSSL and Base58.

    0 讨论(0)
  • 2020-12-08 08:30

    I can recommend you uuencode and uudecode utils you can use them wuth standart ruby function pack:

    str = "\007\007\002\abcde"
    new_string = [str].pack("u")
    original = new_string.unpack("u")
    

    (sample from Hal Fulton's Ruby Way)

    0 讨论(0)
提交回复
热议问题