Saltpack – a modern crypto messaging format based on Dan Bernstein’s NaCl.
Refs: - saltpack.org/ - nacl.cr.yp.to/
- DEFAULT_ENCRYPTION_OPTIONS
The default options for the ::encrypt/::decrypt methods.
- REVISION
Version control revision
- VERSION
Package version
- ZEROS_32
The 32-byte zero string used to create the recipient hashes/MAC keys
armor( input, **options )
Return the input_bytes ascii-armored using the specified options
def self::armor( input, **options )
return Saltpack::Armor.armor( input, **options )
end
calculate_recipient_hash( header_hash, index, keypair1, keypair2 )
Calculate a MAC hash for the recipient at the given index given the specified header_hash, and the two keypairs.
def self::calculate_recipient_hash( header_hash, index, keypair1, keypair2 )
mac_key_nonce_prefix = header_hash[0, 16]
basis = mac_key_nonce_prefix + [ index ].pack('Q>')
nonce1 = basis.dup
nonce1[15] = (nonce1[15].ord & 0xfe).chr
nonce2 = basis.dup
nonce2[15] = (nonce2[15].ord | 0x01).chr
box1 = RbNaCl::Box.new( *keypair1 ).encrypt( nonce1, ZEROS_32 )
box2 = RbNaCl::Box.new( *keypair2 ).encrypt( nonce2, ZEROS_32 )
mac_hash = RbNaCl::Hash.sha512( box1[-16..] + box2[-16..] )
return mac_hash[ 0, 32 ]
end
dearmor( input_chars, **options )
Decode the ascii-armored data from the specified input_chars using the given options.
def self::dearmor( input_chars, **options )
return Saltpack::Armor.dearmor( input_chars, **options )
end
decrypt( message, recipient_key )
Decrypt the given message with the specified recipient_key.
def self::decrypt( message, recipient_key )
msg = Saltpack::Message.read( message, recipient_key )
return msg.decrypt
end
encrypt( message, sender_key, *recipient_public_keys, **options )
Encrypt the given message for the given recipient_public_keys using the sender_key.
def self::encrypt( message, sender_key, *recipient_public_keys, **options )
msg = Saltpack::Message.new( message, sender_key, *recipient_public_keys, **options )
return msg.to_s
end