Difference between revisions of "LlHMAC"

From Second Life Wiki
Jump to navigation Jump to search
m (add wikipedia link)
(If the input changes, so does the output)
 
(4 intermediate revisions by 2 users not shown)
Line 9: Line 9:
|func_footnote=This function supports md5, sha1, sha224, sha256, sha384, sha512 for '''algorithm'''.
|func_footnote=This function supports md5, sha1, sha224, sha256, sha384, sha512 for '''algorithm'''.
|func_desc
|func_desc
|return_text=that is the {{Wikipedia|HMAC|HMAC}} hash of '''msg''' when using hash algorithm '''algorithm''' and secret key '''private_key'''.
|return_text=that is the {{Wikipedia|Base64|Base64-encoded}} {{Wikipedia|HMAC|HMAC}} hash of '''msg''' when using hash algorithm '''algorithm''' and secret key '''private_key'''.
|spec
|spec
|caveats
|caveats
|constants
|constants
|examples=<source lang="lsl2">default
|examples=<syntaxhighlight lang="lsl2">default
{
{
     state_entry()
     state_entry()
     {
     {
        // Key generated using LibreSSL 3.3.6.
         string private_key = "secret key";
        // Generated for demonstration purposes only ;)
         string private_key = "-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAqxXSIhFHzYO9UNEUvMMXwhB4vf32fPirCxxV/w4m88jKPmFH
QQe9DOwj7illmvg+81vzBNGt+uNYy/2zFegUtwvxKCEioeoanRpPcvn9r/d/kXad
WL/DyKJwHbF1EtTfPAZSl6ZIBIYis8HQ/RAln3olS705AmCKBRkbz3cZ+dTzqX1v
7ohqqPPoCaXQFgLTMYnqU8ZTsq1Sl8BwKK735HPmKLCEjZaMn97lvzGHufY/JdRs
dwdRHqKnpe2w2c0AzNpQtjoRCnPtj7cFgCeztjAcbdtuS8ipJTEIuBLWHCVVXIlD
DQ6jJvIEW7tt+6kde/NUskRASd7Rtoy5AeS7cwIDAQABAoIBABwvix/7stWj55Oh
7oWuqoJZTlsWtP4fxaYd8/kCLt6o7NDcG+4VxUqUuNKq1UdzsINNWbsohD46KE3r
LQ7l3kvN1twioV8Ff370b7RkhSvxXX3sib2uUiYCxO/PZZdFpMVx0TeUuHauVpdA
zhpzB4+/gt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Ar9SDcAiL23IQZ/wl/c=
-----END RSA PRIVATE KEY-----";
          
          
         // Supported algorithims for llHmac() include:
         // Supported algorithims for llHMAC() include:
         // md5, sha1, sha224, sha256, sha384, sha512
         // md5, sha1, sha224, sha256, sha384, sha512
          
          
Line 56: Line 28:
          
          
         // For the given private_key/msg/algorithm, expect the HMAC
         // For the given private_key/msg/algorithm, expect the HMAC
         // digest to be 'xK/3hcR1IVpVK9vftoztuVRGZFE='
         // digest to be 'ffCDntkagRO5mIEtd2tYzM2Bg8I='
         llSay(0, "HMAC digest of message '" + msg + "' using algorithm "
         llSay(0, "HMAC digest of message '" + msg + "' using algorithm "
             +  algorithm + " is " + digest);
             +  algorithm + " is " + digest);
     }
     }
}</source>
}</syntaxhighlight>
|helpers
|helpers
|also_functions=
|also_functions=

Latest revision as of 02:31, 7 May 2023

Summary

Function: string llHMAC( string private_key, string msg, string algorithm );
0.0 Forced Delay
10.0 Energy

Returns a string that is the "Wikipedia logo"Base64-encoded "Wikipedia logo"HMAC hash of msg when using hash algorithm algorithm and secret key private_key.

• string private_key
• string msg
• string algorithm

This function supports md5, sha1, sha224, sha256, sha384, sha512 for algorithm.

Examples

default
{
    state_entry()
    {
        string private_key = "secret key";
        
        // Supported algorithims for llHMAC() include:
        // md5, sha1, sha224, sha256, sha384, sha512
        
        string algorithm = "sha1";
        string msg = "Hello, Avatar!";
        
        string digest = llHMAC(private_key, msg, algorithm);
        
        // For the given private_key/msg/algorithm, expect the HMAC
        // digest to be 'ffCDntkagRO5mIEtd2tYzM2Bg8I='
        llSay(0, "HMAC digest of message '" + msg + "' using algorithm "
            +  algorithm + " is " + digest);
    }
}

See Also

Functions

•  llSignRSA
•  llVerifyRSA
•  llSHA1String
•  llSHA256String
•  llMD5String

Deep Notes

Signature

function string llHMAC( string private_key, string msg, string algorithm );