OpenSSL::Digest
allows you to compute message digests (sometimes interchangeably called “hashes”) of arbitrary data that are cryptographically secure, i.e. a Digest
implements a secure one-way function.
One-way functions offer some useful properties. E.g. given two distinct inputs the probability that both yield the same output is highly unlikely. Combined with the fact that every message digest algorithm has a fixed-length output of just a few bytes, digests are often used to create unique identifiers for arbitrary data. A common example is the creation of a unique id for binary documents that are stored in a database.
Another useful characteristic of one-way functions (and thus the name) is that given a digest there is no indication about the original data that produced it, i.e. the only way to identify the original input is to “brute-force” through every possible combination of inputs.
These characteristics make one-way functions also ideal companions for public key signature algorithms: instead of signing an entire document, first a hash of the document is produced with a considerably faster message digest algorithm and only the few bytes of its output need to be signed using the slower public key algorithm. To validate the integrity of a signed document, it suffices to re-compute the hash and verify that it is equal to that in the signature.
You can get a list of all digest algorithms supported on your system by running this command in your terminal:
openssl list -digest-algorithms
Among the OpenSSL
1.1.1 supported message digest algorithms are:
SHA224, SHA256, SHA384, SHA512, SHA512-224 and SHA512-256
SHA3-224, SHA3-256, SHA3-384 and SHA3-512
BLAKE2s256 and BLAKE2b512
Each of these algorithms can be instantiated using the name:
digest = OpenSSL::Digest.new('SHA256')
“Breaking” a message digest algorithm means defying its one-way function characteristics, i.e. producing a collision or finding a way to get to the original data by means that are more efficient than brute-forcing etc. Most of the supported digest algorithms can be considered broken in this sense, even the very popular MD5 and SHA1 algorithms. Should security be your highest concern, then you should probably rely on SHA224, SHA256, SHA384 or SHA512.
data = File.binread('document') sha256 = OpenSSL::Digest.new('SHA256') digest = sha256.digest(data)
data1 = File.binread('file1') data2 = File.binread('file2') data3 = File.binread('file3') sha256 = OpenSSL::Digest.new('SHA256') sha256 << data1 sha256 << data2 sha256 << data3 digest = sha256.digest
Digest
instance data1 = File.binread('file1') sha256 = OpenSSL::Digest.new('SHA256') digest1 = sha256.digest(data1) data2 = File.binread('file2') sha256.reset digest2 = sha256.digest(data2)
Generic error, common for all classes under OpenSSL
module
Generic Error for all of OpenSSL::BN
(big num)
General error for openssl library configuration files. Including formatting, parsing errors, etc.
Document-class: OpenSSL::HMAC
OpenSSL::HMAC
allows computing Hash-based Message Authentication Code (HMAC
). It is a type of message authentication code (MAC) involving a hash function in combination with a key. HMAC
can be used to verify the integrity of a message as well as the authenticity.
OpenSSL::HMAC
has a similar interface to OpenSSL::Digest
.
key = "key" data = "message-to-be-authenticated" mac = OpenSSL::HMAC.hexdigest("SHA256", key, data) #=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"
data1 = File.binread("file1") data2 = File.binread("file2") key = "key" hmac = OpenSSL::HMAC.new(key, 'SHA256') hmac << data1 hmac << data2 mac = hmac.digest
This class works in conjunction with Psych::Parser
to build an in-memory parse tree that represents a YAML
document.
parser = Psych::Parser.new Psych::TreeBuilder.new parser.parse('--- foo') tree = parser.handler.root
See Psych::Handler
for documentation on the event methods used in this class.
UDP/IP address information used by Socket.udp_server_loop
.
The superclass for all exceptions raised by Ruby/zlib.
The following exceptions are defined as subclasses of Zlib::Error
. These exceptions are raised when zlib library functions return with an error status.
Subclass of Zlib::Error
when zlib returns a Z_DATA_ERROR.
Usually if a stream was prematurely freed.
Subclass of Zlib::Error
When zlib returns a Z_MEM_ERROR, usually if there was not enough memory.
Subclass of Zlib::Error
when zlib returns a Z_BUF_ERROR.
Usually if no progress is possible.
Subclass of Zlib::Error
When zlib returns a Z_VERSION_ERROR, usually if the zlib library version is incompatible with the version assumed by the caller.
Zlib::GzipReader
is the class for reading a gzipped file. GzipReader
should be used as an IO
, or -IO-like, object.
Zlib::GzipReader.open('hoge.gz') {|gz| print gz.read } File.open('hoge.gz') do |f| gz = Zlib::GzipReader.new(f) print gz.read gz.close end
Method
Catalogue The following methods in Zlib::GzipReader
are just like their counterparts in IO
, but they raise Zlib::Error
or Zlib::GzipFile::Error
exception if an error was found in the gzip file.
Be careful of the footer of the gzip file. A gzip file has the checksum of pre-compressed data in its footer. GzipReader
checks all uncompressed data against that checksum at the following cases, and if it fails, raises Zlib::GzipFile::NoFooter
, Zlib::GzipFile::CRCError
, or Zlib::GzipFile::LengthError
exception.
When an reading request is received beyond the end of file (the end of compressed data). That is, when Zlib::GzipReader#read
, Zlib::GzipReader#gets
, or some other methods for reading returns nil.
When Zlib::GzipFile#close
method is called after the object reaches the end of file.
When Zlib::GzipReader#unused
method is called after the object reaches the end of file.
The rest of the methods are adequately described in their own documentation.
Objects of class File::Stat
encapsulate common status information for File
objects. The information is recorded at the moment the File::Stat
object is created; changes made to the file after that point will not be reflected. File::Stat
objects are returned by IO#stat
, File::stat
, File#lstat
, and File::lstat
. Many of these methods return platform-specific values, and not all values are meaningful on all systems. See also Kernel#test
.
exception to wait for reading by EAGAIN. see IO.select
.
exception to wait for reading by EWOULDBLOCK. see IO.select
.
exception to wait for writing by EINPROGRESS. see IO.select
.
The InstructionSequence
class represents a compiled sequence of instructions for the Virtual Machine used in MRI. Not all implementations of Ruby may implement this class, and for the implementations that implement it, the methods defined and behavior of the methods can change in any version.
With it, you can get a handle to the instructions that make up a method or a proc, compile strings of Ruby code down to VM instructions, and disassemble instruction sequences to strings for easy inspection. It is mostly useful if you want to learn how YARV works, but it also lets you control various settings for the Ruby iseq compiler.
You can find the source for the VM instructions in insns.def
in the Ruby source.
The instruction sequence results will almost certainly change as Ruby changes, so example output in this documentation may be different from what you see.
Of course, this class is MRI specific.
The DidYouMean::Formatter
is the basic, default formatter for the gem. The formatter responds to the message_for
method and it returns a human readable string.
The DidYouMean::Formatter
is the basic, default formatter for the gem. The formatter responds to the message_for
method and it returns a human readable string.
The DidYouMean::Formatter
is the basic, default formatter for the gem. The formatter responds to the message_for
method and it returns a human readable string.
spell checker for a dictionary that has a tree structure, see doc/tree_spell_checker_api.md