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)
Subclass of Zlib::Error
When zlib returns a Z_NEED_DICT if a preset dictionary is needed at this point.
Used by Zlib::Inflate.inflate
and Zlib.inflate
Exception
raised when there is an invalid encoding detected
Response class for Not Modified
responses (status code 304).
Indicates that the resource has not been modified since the version specified by the request headers.
References:
Response class for Payment Required
responses (status code 402).
Reserved for future use.
References:
Response class for Proxy Authentication Required
responses (status code 407).
The client must first authenticate itself with the proxy.
References:
Response class for Length Required
responses (status code 411).
The request did not specify the length of its content, which is required by the requested resource.
References:
Response class for Precondition Failed
responses (status code 412).
The server does not meet one of the preconditions specified in the request headers.
References:
Response class for Unsupported Media Type
responses (status code 415).
The request entity has a media type which the server or resource does not support.
References:
Response class for Upgrade Required
responses (status code 426).
The client should switch to the protocol given in the Upgrade header field.
References:
Response class for Network Authentication Required
responses (status code 511).
The client needs to authenticate to gain network access.
References:
Represents forwarding all arguments to this method to another method.
def foo(...) bar(...) ^^^ end
Represents the use of the forwarding parameter in a method, block, or lambda declaration.
def foo(...) ^^^ end
Represents the use of the ‘super` keyword without parentheses or arguments.
super ^^^^^
Represents a required keyword parameter to a method, block, or lambda definition.
def a(b: ) ^^ end
Represents a required parameter to a method, block, or lambda definition.
def a(b) ^ end
Represents an expression modified with a rescue.
foo rescue nil ^^^^^^^^^^^^^^
Represents the use of the ‘__ENCODING__` keyword.
__ENCODING__ ^^^^^^^^^^^^
A Requirement
is a set of one or more version restrictions. It supports a few (=, !=, >, <, >=, <=, ~>
) different restriction operators.
See Gem::Version
for a description on how versions and requirements work together in RubyGems.
Outputs code with highlighted lines
Whatever is passed to this class will be rendered even if it is “marked invisible” any filtering of output should be done before calling this class.
DisplayCodeWithLineNumbers.new( lines: lines, highlight_lines: [lines[2], lines[3]] ).call # => 1 2 def cat > 3 Dir.chdir > 4 end 5 end 6
Used for formatting invalid blocks