Module: CcipherFactory::AsymKeyCipher::ECCEncrypt
- Includes:
- Common, Compression::CompressionHelper, TR::CondUtils
- Defined in:
- lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb
Defined Under Namespace
Classes: ECCCipherError
Instance Attribute Summary collapse
-
#recipient_key ⇒ Object
Returns the value of attribute recipient_key.
-
#sender_keypair ⇒ Object
Returns the value of attribute sender_keypair.
Instance Method Summary collapse
- #encrypt_final ⇒ Object
- #encrypt_init(opts = { }, &block) ⇒ Object
- #encrypt_update(val) ⇒ Object
- #logger ⇒ Object
Methods included from Compression::CompressionHelper
#compress_data_if_active, #compression_off, #compression_on, #compressor, #decompress_data_if_active, #decompressor, #decompressor_from_encoded, #encode_null_compressor, #is_compression_on?
Methods included from Common
#attach_mode, #cleanup_intOutputBuf, #cleanup_intOutputFile, #detach_mode, #disposeOutput, #intOutputBuf, #intOutputFile, #is_attach_mode?, #is_output_given?, #output, #output_obj, #sanitize_symbol, #write_to_output
Instance Attribute Details
#recipient_key ⇒ Object
Returns the value of attribute recipient_key.
17 18 19 |
# File 'lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb', line 17 def recipient_key @recipient_key end |
#sender_keypair ⇒ Object
Returns the value of attribute sender_keypair.
17 18 19 |
# File 'lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb', line 17 def sender_keypair @sender_keypair end |
Instance Method Details
#encrypt_final ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb', line 72 def encrypt_final cipherConfig = @cipher.encrypt_final intOutputFile.rewind while not intOutputFile.eof? write_to_output(intOutputFile.read) end cleanup_intOutputFile pkBin = @sender_keypair.public_key.to_bin ts = BinStruct.instance.struct(:ecc_cipher) ts.sender_public = @sender_keypair.public_key.to_bin ts.cipher_config = cipherConfig ts.key_config = @sessKey.encoded ts.encoded end |
#encrypt_init(opts = { }, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb', line 19 def encrypt_init(opts = { }, &block) #@sender = opts[:sender_keypair] #recpPub = opts[:recipient_public] recpPub = @recipient_key raise ECCCipherError, "Receipient public key is required" if is_empty?(recpPub) raise ECCCipherError, "Cipher requires output to be set" if not is_output_given? raise ECCCipherError, "Sender Keypair is required" if is_empty?(@sender_keypair) #if is_empty?(@sender_keypair) # @sender_keypair = AsymKeyGenerator.generate(:ecc) #end #derived = @sender_keypair.dh_compute_key(recpPub) #logger.debug "sender : #{@sender_keypair.inspect} / #{@sender_keypair.private?}" #logger.debug "recp : #{recpPub.inspect}" derived = @sender_keypair.derive_dh_shared_secret(recpPub) @sessKey = SymKeyGenerator.derive(:aes, 256) do |ops| case ops when :password derived end end @cipher = SymKeyCipher.encryptor @cipher.output(intOutputFile) @cipher.key = @sessKey if is_compression_on? logger.debug "Turning on compression" @cipher.compression_on else logger.debug "Compression not active" @cipher.compression_off end @cipher.encrypt_init if block instance_eval(&block) encrypt_final else self end end |
#encrypt_update(val) ⇒ Object
68 69 70 |
# File 'lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb', line 68 def encrypt_update(val) @cipher.encrypt_update(val) end |
#logger ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/ccipher_factory/asymkey_cipher/ecc/ecc_encrypt.rb', line 91 def logger if @logger.nil? @logger = Tlogger.new @logger.tag = :ecc_enc end @logger end |