The SHA1 function takes a String as input and returns the hash of the input as a Hex- or Base64-encoded string, arrived at via the SHA-1 hashing algorithm.
This function requires a single String as input. As an option, it also accepts another string that define if Hex or Base64 encoding will to be used to calculate the output: a string that gives the hash of the first input, as calculated by the SHA-1 hashing algorithm.
Declaration
SHA1(string, encode) -> hash
Parameters
string (required, type:string)
Any string.
encode (optional, type:string, default: "Hex")
The string "Hex" or "Base64". This defines if the hash of string will be Hex- or Base64-encoded, respectively.
If no value is given for encode, SHA1 will return the Hex-encoded hash. If a value other than "Hex" or "Base64" is given for encode, SHA1 will throw an error.
Return Values
hash(type: string)
The hash of the input as calculated by the SHA-1 hashing algorithm.
Examples
The following example returns the Hex-encoded hash of the string "This is a string." as calculated by the SHA-1 hashing algorithm:
SHA1("This is a string.") => "dd603477ba4c236ec5cfb4e4a34162d8d687850"
The following example also returns the Hex-encoded hash of the string "This is a string." as calculated by the SHA-1 hashing algorithm. Note that it returns the same output as the above example; there is no difference in output between explicitly defining "Hex" as the value for encode and not defining encode at all:
SHA1("This is a string.", "Hex") => "dd603477ba4c236ec5cfb4e4a34162d8d687850"
The following example returns the Base64-encoded hash of the string "This is a string." as calculated by the SHA-1 hashing algorithm. Note how this differs from the above examples:
SHA1("This is a string.", "Base64") => "3WA0d7pMI27Fz7TkpDQWLY1oeFA="
The following example returns the hash of the email "[email protected]" as calculated by the SHA-1 hashing algorithm. Note that within Airscript, an email is a subcategory of string:
SHA1("[email protected]") => "4ad08d34a9b1d589cc80a220a67f115ee6b0dd7d"