Sha256: 6ad16381f0195c51d30c3229b3fb0e85e15719d6ffdc662825ab56065fea505c

Contents?: true

Size: 753 Bytes

Versions: 57

Compression:

Stored size: 753 Bytes

Contents

class Kumogata::Crypt
  ALGORITHM = 'aes256'
  PASSWORD_CHARS = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789_*;:@{}()[]#$%&=-'

  class << self
    def encrypt(pass, str)
      IO.popen("openssl enc -e -#{ALGORITHM} -pass pass:#{enquote(pass)}", "r+") {|io|
        io.print str
        io.close_write
        io.read
      }.encode64
    end

    def decrypt(pass, str)
      IO.popen("openssl enc -d -#{ALGORITHM} -pass pass:#{enquote(pass)}", "r+") {|io|
        io.print Base64.decode64(str)
        io.close_write
        io.read
      }
    end

    def mkpasswd(n)
      PASSWORD_CHARS.split(//).sample(n).join
    end

    private

    def enquote(str)
      "'" + str.gsub("'", %!'"'"'!) + "'"
    end
  end # of class methods
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
kumogata-0.5.12 lib/kumogata/crypt.rb
kumogata-0.5.11 lib/kumogata/crypt.rb
kumogata-0.5.10 lib/kumogata/crypt.rb
kumogata-0.5.9 lib/kumogata/crypt.rb
kumogata-0.5.8 lib/kumogata/crypt.rb
kumogata-0.5.7 lib/kumogata/crypt.rb
kumogata-0.5.6 lib/kumogata/crypt.rb
kumogata-0.5.5 lib/kumogata/crypt.rb
kumogata-0.5.4 lib/kumogata/crypt.rb
kumogata-0.5.3 lib/kumogata/crypt.rb
kumogata-0.5.2 lib/kumogata/crypt.rb
kumogata-0.5.2.beta2 lib/kumogata/crypt.rb
kumogata-0.5.2.beta lib/kumogata/crypt.rb
kumogata-0.5.1 lib/kumogata/crypt.rb
kumogata-0.5.0 lib/kumogata/crypt.rb
kumogata-0.4.19 lib/kumogata/crypt.rb
kumogata-0.4.18 lib/kumogata/crypt.rb
kumogata-0.4.17 lib/kumogata/crypt.rb
kumogata-0.4.16 lib/kumogata/crypt.rb
kumogata-0.4.15 lib/kumogata/crypt.rb