class Crypt::Signer

Overview

Sign and verify given data.

Defined in:

signer.cr

Constant Summary

INVALID_SIGN = "Not valid"
SIGN_SEP = "__--"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(secret : String, digest = :sha1) #

Create a Signer instance.


Class Method Detail

def self.parse_data_and_digest(signed_data) : Tuple(String, String) #

Instance Method Detail

def sign(value : String | Bytes) : String #

Generates signed data. Returns an URL and filename safe alphabet (RFC 4648).


def valid?(data, digest) : Bool #

Compare data and digest.


def verify(signed_data, error_message = INVALID_SIGN) : String #

Verify and decode. error_message allows to customize the error message when the signature is not valid.


def verify_and_decode(signed_data : String) : String? #

Verify and decode.

It is recommended to use #verify which has a more precise return (returns String or raises a SignatureError).

def verify_raw(signed_data : String, error_message = INVALID_SIGN) : Bytes #

Verify and decode. error_message allows to customize the error message when the signature is not valid.

This method can produce a different error message than error_message.

def verify_raw(signed_data : Bytes, error_message = INVALID_SIGN) : Bytes #

Verify and decode. error_message allows to customize the error message when the signature is not valid.

This method can produce a different error message than error_message.