{
    "mode": "perldoc",
    "parameter": "Crypt::AuthEnc::GCM",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Crypt%3A%3AAuthEnc%3A%3AGCM/json",
    "generated": "2026-10-10T04:35:39Z",
    "synopsis": "### OO interface\nuse Crypt::AuthEnc::GCM;\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\nmy $tag = $ae->encryptdone();\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\nmy $tag = $ae->decryptdone();\ndie \"decrypt failed\" unless $tag eq $expectedtag;\n#or\nmy $result = $ae->decryptdone($expectedtag); # 0 or 1\n### functional interface\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\nmy ($ciphertext, $tag) = gcmencryptauthenticate('AES', $key, $iv, $adata, $plaintext);\nmy $plaintext = gcmdecryptverify('AES', $key, $iv, $adata, $ciphertext, $tag);",
    "sections": {
        "NAME": {
            "content": "Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "### OO interface\nuse Crypt::AuthEnc::GCM;\n\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\nmy $tag = $ae->encryptdone();\n\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\nmy $tag = $ae->decryptdone();\ndie \"decrypt failed\" unless $tag eq $expectedtag;\n\n#or\nmy $result = $ae->decryptdone($expectedtag); # 0 or 1\n\n### functional interface\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\n\nmy ($ciphertext, $tag) = gcmencryptauthenticate('AES', $key, $iv, $adata, $plaintext);\nmy $plaintext = gcmdecryptverify('AES', $key, $iv, $adata, $ciphertext, $tag);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Galois/Counter Mode (GCM) - provides encryption and authentication.\n",
            "subsections": []
        },
        "EXPORT": {
            "content": "Nothing is exported by default.\n\nYou can export selected functions:\n\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "gcmencryptauthenticate\nmy ($ciphertext, $tag) = gcmencryptauthenticate($cipher, $key, $iv, $adata, $plaintext);\n\n# $cipher .. 'AES' or name of any other cipher with 16-byte block len\n# $key ..... AES key of proper length (128/192/256bits)\n# $iv ...... initialization vector\n# $adata ... additional authenticated data\n\ngcmdecryptverify\nmy $plaintext = gcmdecryptverify($cipher, $key, $iv, $adata, $ciphertext, $tag);\n# on error returns undef\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\nmy $ae = Crypt::AuthEnc::GCM->new($cipher, $key);\n#or\nmy $ae = Crypt::AuthEnc::GCM->new($cipher, $key, $iv);\n\n# $cipher .. 'AES' or name of any other cipher\n# $key ..... encryption key of proper length\n# $iv ...... initialization vector (optional, you can set it later via ivadd method)\n\nivadd\nSet initialization vector (IV).\n\n$ae->ivadd($ivdata);                        #can be called multiple times\n\nadataadd\nAdd additional authenticated data. Can be called after all \"ivadd\" calls but before the first\n\"encryptadd\" or \"decryptadd\".\n\n$ae->adataadd($aaddata);                    # can be called multiple times\n\nencryptadd\n$ciphertext = $ae->encryptadd($data);        # can be called multiple times\n\nencryptdone\n$tag = $ae->encryptdone();                   # returns $tag value\n\ndecryptadd\n$plaintext = $ae->decryptadd($ciphertext);   # can be called multiple times\n\ndecryptdone\nmy $tag = $ae->decryptdone;           # returns $tag value\n#or\nmy $result = $ae->decryptdone($tag);  # returns 1 (success) or 0 (failure)\n\nreset\n$ae->reset;\n\nclone\nmy $aenew = $ae->clone;\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   CryptX, Crypt::AuthEnc::CCM, Crypt::AuthEnc::EAX, Crypt::AuthEnc::OCB\n\n*   <https://en.wikipedia.org/wiki/Galois/CounterMode>\n",
            "subsections": []
        }
    },
    "summary": "Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode",
    "flags": [],
    "examples": [],
    "see_also": []
}