Name
SPVM::Digest::SHA - SHA-1/224/256/384/512
Description
The SPVM::Digest::SHA of SPVM has methods for SHA-1/224/256/384/512.
Usage
use Digest::SHA;
my $digest = Digest::SHA->sha1($data);
my $digest = Digest::SHA->sha1_hex($data);
my $digest = Digest::SHA->sha1_base64($data);
my $digest = Digest::SHA->sha256($data);
my $digest = Digest::SHA->sha384_hex($data);
my $digest = Digest::SHA->sha512_base64($data);
Object Oriented Programming:
my $sha = Digest::SHA->new($alg);
$sha->add($data);
my $sha_copy = $sha->clone;
my $digest = $sha->digest;
my $digest = $sha->hexdigest;
my $digest = $sha->b64digest;
Class Methods
sha1
static method sha1 : string ($data : string);
Receive the input date and return its SHA-1 digest encoded as a binary string.
sha1_hex
static method sha1_hex : string ($data : string);
Receive the input date and return its SHA-1 digest encoded as a hexadecimal string.
sha1_base64
static method sha1_base64 : string ($data : string);
Receive the input date and return its SHA-1 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
sha224
static method sha224 : string ($data : string);
Receive the input date and return its SHA-224 digest encoded as a binary string.
sha224_hex
static method sha224_hex : string ($data : string);
Receive the input date and return its SHA-224 digest encoded as a hexadecimal string.
sha224_base64
static method sha224_base64 : string ($data : string);
Receive the input date and return its SHA-224 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
sha256
static method sha256 : string ($data : string);
Receive the input date and return its SHA-256 digest encoded as a binary string.
sha256_hex
static method sha256_hex : string ($data : string);
Receive the input date and return its SHA-256 digest encoded as a hexadecimal string.
sha256_base64
static method sha256_base64 : string ($data : string);
Receive the input date and return its SHA-256 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
sha384
static method sha384 : string ($data : string);
Receive the input date and return its SHA-384 digest encoded as a binary string.
sha384_hex
static method sha384_hex : string ($data : string);
Receive the input date and return its SHA-384 digest encoded as a hexadecimal string.
sha384_base64
static method sha384_base64 : string ($data : string);
Receive the input date and return its SHA-384 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
sha512
static method sha512 : string ($data : string);
Receive the input date and return its SHA-512 digest encoded as a binary string.
sha512_hex
static method sha512_hex : string ($data : string);
Receive the input date and return its SHA-512 digest encoded as a hexadecimal string.
sha512_base64
static method sha512_base64 : string ($data : string);
Receive the input date and return its SHA-512 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
sha512224
static method sha512224 : string ($data : string);
Receive the input date and return its SHA-512/224 digest encoded as a binary string.
sha512224_hex
static method sha512224_hex : string ($data : string);
Receive the input date and return its SHA-512/224 digest encoded as a hexadecimal string.
sha512224_base64
static method sha512224_base64 : string ($data : string);
Receive the input date and return its SHA-512/224 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
sha512256
static method sha512256 : string ($data : string);
Receive the input date and return its SHA-512/256 digest encoded as a binary string.
sha512256_hex
static method sha512256_hex : string ($data : string);
Receive the input date and return its SHA-512/256 digest encoded as a hexadecimal string.
sha512256_base64
static method sha512256_base64 : string ($data : string);
Receive the input date and return its SHA-512/256 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha1
static method hmac_sha1 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-1 digest encoded as a binary string.
hmac_sha1_hex
static method hmac_sha1_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-1 digest encoded as a hexadecimal string.
hmac_sha1_base64
static method hmac_sha1_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-1 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha224
static method hmac_sha224 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-224 digest encoded as a binary string.
hmac_sha224_hex
static method hmac_sha224_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-224 digest encoded as a hexadecimal string.
hmac_sha224_base64
static method hmac_sha224_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-224 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha256
static method hmac_sha256 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-256 digest encoded as a binary string.
hmac_sha256_hex
static method hmac_sha256_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-256 digest encoded as a hexadecimal string.
hmac_sha256_base64
static method hmac_sha256_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-256 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha384
static method hmac_sha384 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-384 digest encoded as a binary string.
hmac_sha384_hex
static method hmac_sha384_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-384 digest encoded as a hexadecimal string.
hmac_sha384_base64
static method hmac_sha384_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-384 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha512
static method hmac_sha512 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512 digest encoded as a binary string.
hmac_sha512_hex
static method hmac_sha512_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512 digest encoded as a hexadecimal string.
hmac_sha512_base64
static method hmac_sha512_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha512224
static method hmac_sha512224 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512/224 digest encoded as a binary string.
hmac_sha512224_hex
static method hmac_sha512224_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512/224 digest encoded as a hexadecimal string.
hmac_sha512224_base64
static method hmac_sha512224_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512/224 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
hmac_sha512256
static method hmac_sha512256 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512/256 digest encoded as a binary string.
hmac_sha512256_hex
static method hmac_sha512256_hex : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512/256 digest encoded as a hexadecimal string.
hmac_sha512256_base64
static method hmac_sha512256_base64 : string ($data : string, $key : string);
Receive the input date and return its HMAC-SHA-512/256 digest encoded as a Base64 string.
See "PADDING OF BASE64 DIGESTS" in Digest::SHA for details about padding.
new
static method new : Digest::SHA ($alg : int);
Returns a new Digest::SHA
object. Allowed values for $alg are 1, 224, 256, 384, 512, 512224, or 512256. It's also possible to use common string representations of the algorithm (e.g. "sha256", "SHA-384"). If the argument is missing, SHA-1 will be used by default.
Instance Methods
hashsize
method hashsize : int ();
Returns the number of digest bits for this object. The values are 160, 224, 256, 384, 512, 224, and 256 for SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256, respectively.
algorithm
method algorithm : int ();
Returns the digest algorithm for this object. The values are 1, 224, 256, 384, 512, 512224, and 512256 for SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256, respectively.
add
method add : void ($date : string);
Use the input data to update the current digest state. In other words, the following statements have the same effect:
$sha->add("a"); $sha->add("b"); $sha->add("c");
$sha->add("abc");
digest
method digest : string ();
Returns the digest encoded as a binary string.
b64digest
method hexdigest : string ();
Returns the digest encoded as a hexadecimal string.
b64digest
method b64digest : string ();
Returns the digest encoded as a Base64 string.
method clone : Digest::SHA ();
Returns a duplicate copy of the object.
See Also
Digest::SHA
SPVM::Digest::SHA
is a Perl's Digest::SHA porting to SPVM.
Repository
Author
Yuki Kimoto kimoto.yuki@gmail.com
Contributors
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License