Method: GPGME::Crypto#decrypt
- Defined in:
- lib/gpgme/crypto.rb
#decrypt(cipher, options = {}) ⇒ GPGME::Data
Decrypts a previously encrypted element
crypto.decrypt cipher, , &block
Must have the appropiate key to be able to decrypt, of course. Returns a Data object which can then be read.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/gpgme/crypto.rb', line 164 def decrypt(cipher, = {}) = .merge plain_data = Data.new([:output]) cipher_data = Data.new(cipher) GPGME::Ctx.new() do |ctx| begin ctx.decrypt_verify(cipher_data, plain_data) rescue GPGME::Error::UnsupportedAlgorithm => exc exc.algorithm = ctx.decrypt_result.unsupported_algorithm raise exc rescue GPGME::Error::WrongKeyUsage => exc exc.key_usage = ctx.decrypt_result.wrong_key_usage raise exc end verify_result = ctx.verify_result if verify_result && block_given? verify_result.signatures.each do |signature| yield signature end end end plain_data.seek(0) plain_data end |