Simple Encryption in Ruby without external gems

前端 未结 9 931
庸人自扰
庸人自扰 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:03

    Optional method for encryption and decryption

    gem 'activesupport'
    
    require 'active_support'
    
    key = SecureRandom.random_bytes(32)
    crypt = ActiveSupport::MessageEncryptor.new(key)
    encrypted_data = crypt.encrypt_and_sign("your password")
    password = crypt.decrypt_and_verify(encrypted_data)
    

提交回复
热议问题