
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
mongoid-encryptor encrypts and decrypts one or more fields in a Mongoid model.
Put this line in your Gemfile:
gem 'mongoid-encryptor', :require => 'mongoid/encryptor'
Then bundle:
$ bundle
Set up SHA encrypted field in models like this:
class Credential
include Mongoid::Document
include Mongoid::Encryptor
field :password
encrypts :password
end
>> c = Credential.new
=> #<Credential _id: 4d6383aeb2de3cbea1000001, password: nil>
>> c.password = 'this is a secret'
=> "this is a secret"
>> c.password.encrypted?
=> false
>> c.save
=> true
>> c.password
=> "70a202166f0a78defe464d810f30b50b767cb89a"
>> c.password.encrypted?
=> true
>> c.password.cipher.salt
=> "salt"
>> c.password == 'this is a secret'
=> true
Set up Symmetric encrypted field in models like this:
class Credential
include Mongoid::Document
include Mongoid::Encryptor
field :password
encrypts :password, :mode => :symmetric, :password => 'key'
end
>> c = Credential.new
=> #<Credential _id: 4d638b6db2de3cc2ca000001, password: nil>
>> c.password = 'this is a secret'
=> "this is a secret"
>> c.password.encrypted?
=> false
>> c.save
=> true
>> c.password
=> "y3HnNrU0HviAl3aw2sWH1KttBLsCLYP1\n"
>> c.password.encrypted?
=> true
>> c.password.cipher
=> #<EncryptedStrings::SymmetricCipher:0x000001016b1c08 @algorithm="DES-EDE3-CBC", @password="key">
>> c.password.cipher.password
=> "key"
>> c.password == 'this is a secret'
=> true
Set up Asymmetric encrypted field in models like this:
class Credential
include Mongoid::Document
include Mongoid::Encryptor
field :password
encrypts :password, :mode => :asymmetric,
:private_key_file => '/path/to/private_key',
:public_key_file => '/path/to/public_key'
end
>> c = Credential.new
=> #<Credential _id: 4d638ceab2de3cc3c1000001, password: nil>
>> c.password = 'this is a secret'
=> "this is a secret"
>> c.password.encrypted?
=> false
>> c.save
=> true
>> c.password
=> "ha/2EacZTmvAIHOSjFEshM+9UHUItB/wGKJ5ftClQDllA9SOBJJazTlsMS9m\nPd5W3goZbY9V2dDdNo4NgQ0e8VsG0dpcvOIrua/ye+jX3e+0ocevcnOH9PL9\n8C5P8caOD/sKlKLTI0Dr1v/6d/f0Q4UuPQyTh3d4aEWyagypWyQ=\n"
>> c.password.encrypted?
=> true
>> c.password == 'this is a secret'
=> true
You can generate keypair like this:
$ openssl genrsa -des3 -out private 1024 # generate private key
$ openssl rsa -in private -pubout -out public # generate public key
$ mv private private.bak
$ openssl rsa -in private.bak -out private # remove passphrase from private key
$ ls -l
-rw-r--r-- 1 juno staff 887 2 22 19:20 private
-rw-r--r-- 1 juno staff 963 2 22 19:19 private.bak
-rw-r--r-- 1 juno staff 272 2 22 19:19 public
github/juno or @junya.
(c) 2011 Junya Ogura. See LICENSE.txt for further details.
FAQs
Unknown package
We found that mongoid-encryptor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.