diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index daf8543..8e95297 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -509,7 +509,7 @@ class Cli 'password' => @mpw.get_password(item.id), 'protocol' => item.protocol, 'port' => item.port, - 'otp_key' => @mpw.get_otp_code(item.id), + 'otp_key' => @mpw.get_otp_key(item.id), 'comment' => item.comment, 'last_edit' => item.last_edit, 'created' => item.created, @@ -521,7 +521,7 @@ class Cli File.open(file, 'w') {|f| f << data.to_yaml} - puts "#{I18n.t('export.export.valid', file)}".green + puts "#{I18n.t('export.valid', file)}".green rescue Exception => e puts "#{I18n.t('display.error')} #17: #{e}".red end diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 10c57d0..c2befb1 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -403,9 +403,23 @@ class MPW # args: id -> the item id # key -> the new key def set_otp_key(id, key) - @otp_keys[id] = encrypt(key) + if not key.to_s.empty? + @otp_keys[id] = encrypt(key.to_s) + end end + # Get an opt key + # args: id -> the item id + # key -> the new key + def get_otp_key(id) + if @otp_keys.has_key?(id) + return decrypt(@otp_keys[id]) + else + return nil + end + end + + # Get an otp code # @args: id -> the item id # @rtrn: an otp code