php
type_error
ai_generated
true
Warning: sodium_crypto_sign_secretkey(): Argument #1 ($key_pair) must be an opaque key pair (SODIUM_CRYPTO_SIGN_KEYPAIR) in /var/www/app/src/Auth/Ed25519Signer.php on line 34
ID: php/sodium-crypto-sign-keypair-invalid
85%Fix Rate
83%Confidence
1Evidence
2024-09-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| PHP 8.1.29 | active | — | — | — |
| PHP 8.2.17 | active | — | — | — |
| PHP 8.3.4 | active | — | — | — |
Root Cause
Passing a raw string or invalid object to sodium_crypto_sign_secretkey() instead of a valid key pair generated by sodium_crypto_sign_keypair().
generic中文
向 sodium_crypto_sign_secretkey() 传递了原始字符串或无效对象,而不是由 sodium_crypto_sign_keypair() 生成的有效密钥对。
Official Documentation
https://www.php.net/manual/en/function.sodium-crypto-sign-secretkey.phpWorkarounds
-
90% success Always generate key pairs with sodium_crypto_sign_keypair() and store the entire binary output, then reconstruct with sodium_crypto_sign_secretkey(): $keyPair = sodium_crypto_sign_keypair(); $secretKey = sodium_crypto_sign_secretkey($keyPair);
Always generate key pairs with sodium_crypto_sign_keypair() and store the entire binary output, then reconstruct with sodium_crypto_sign_secretkey(): $keyPair = sodium_crypto_sign_keypair(); $secretKey = sodium_crypto_sign_secretkey($keyPair);
-
85% success If loading from storage, use sodium_crypto_sign_keypair_from_secretkey_and_publickey() with both parts: $keyPair = sodium_crypto_sign_keypair_from_secretkey_and_publickey($secret, $public);
If loading from storage, use sodium_crypto_sign_keypair_from_secretkey_and_publickey() with both parts: $keyPair = sodium_crypto_sign_keypair_from_secretkey_and_publickey($secret, $public);
中文步骤
Always generate key pairs with sodium_crypto_sign_keypair() and store the entire binary output, then reconstruct with sodium_crypto_sign_secretkey(): $keyPair = sodium_crypto_sign_keypair(); $secretKey = sodium_crypto_sign_secretkey($keyPair);
If loading from storage, use sodium_crypto_sign_keypair_from_secretkey_and_publickey() with both parts: $keyPair = sodium_crypto_sign_keypair_from_secretkey_and_publickey($secret, $public);
Dead Ends
Common approaches that don't work:
-
85% fail
Base64-decoding the key pair string and passing the raw bytes directly, assuming it's the same as the key pair object, fails because sodium expects a specific internal structure.
-
70% fail
Using sodium_crypto_sign_seed_keypair() with an invalid seed length (not exactly 32 bytes) produces a different error but still doesn't fix the type issue.