2

次の属性を持つ***ユーザーモデル***のアクティブレコードの暗号化にhttps://github.com/attr-encrypted/attr_encryptedを使用しています。

 
  activation_hash 文字列  
  詳細文字列  
  メール文字列  
  IMEIストリング  
  パスワード文字列  
  registration_id 文字列  
  secure_hash 文字列  

これらの属性を次のように使用しました

attr_encrypted_options.merge!(:prefix => 'android_', :suffix => '_sheild')  
attr_encrypted :activation_hash, :key => Getter::encryption_key, :encode => true  
attr_encrypted :active, :key => Getter::encryption_key, :encode => true  
attr_encrypted :code, :key => Getter::encryption_key, :encode => true  
attr_encrypted :details, :key => Getter::encryption_key, :encode => true  
attr_encryptor :email, :key => "this is awais"  
attr_encrypted :password, :key => Getter::encryption_key, :encode => true  
attr_encrypted :registration_id, :key => Getter::encryption_key, :encode => true  
attr_encrypted :secure_hash, :key => Getter::encryption_key, :encode => true
attr_encrypted :imei, :key => Getter::encryption_key, :encode => true

attr_encrypted wiki で述べ​​たように、データベースに保存されているレコードの空の文字列を保存すると。

Getter では、一般的な暗号化キー メソッドを追加しました。

    module Getter

      def self.encryption_key
        keys = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv
        return keys
      end
    end

ユーザーモデルに追加した暗号化された属性を使用して移行を追加する必要がありますか..アクティブレコードデータを暗号化し、そのフィールドをデータベースに保存することを目的としています。取得すると、復号化されたレコードを取得できますが、DBレベルではこれらのレコードにアクセスできません.

私が間違っていることを教えてください?? gemを切り替える必要がありますか??

あなたの提案は高く評価されています

4

1 に答える 1

2

attr_encrypted ドキュメントによると:

デフォルトでは、暗号化された属性名は encrypted_#{attribute} です (たとえば、attr_encrypted :email は encrypted_email という名前の属性を作成します)。そのため、暗号化された属性をデータベースに保存する場合は、encrypted_#{attribute} フィールドがテーブルに存在することを確認する必要があります。

期待される形式でフィールドに名前を付けていないようです。

于 2014-06-17T10:12:55.507 に答える