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.4.14 lib/kumogata/crypt.rb
kumogata-0.4.13 lib/kumogata/crypt.rb
kumogata-0.4.12 lib/kumogata/crypt.rb
kumogata-0.4.11 lib/kumogata/crypt.rb
kumogata-0.4.10 lib/kumogata/crypt.rb
kumogata-0.4.9 lib/kumogata/crypt.rb
kumogata-0.4.8 lib/kumogata/crypt.rb
kumogata-0.4.7 lib/kumogata/crypt.rb
kumogata-0.4.6 lib/kumogata/crypt.rb
kumogata-0.4.5 lib/kumogata/crypt.rb
kumogata-0.4.4 lib/kumogata/crypt.rb
kumogata-0.4.3 lib/kumogata/crypt.rb
kumogata-0.4.2 lib/kumogata/crypt.rb
kumogata-0.4.1 lib/kumogata/crypt.rb
kumogata-0.4.0 lib/kumogata/crypt.rb
kumogata-0.3.14 lib/kumogata/crypt.rb
kumogata-0.3.13 lib/kumogata/crypt.rb
kumogata-0.3.12 lib/kumogata/crypt.rb
kumogata-0.3.11 lib/kumogata/crypt.rb
kumogata-0.3.10 lib/kumogata/crypt.rb