SodiumException 密钥应该是 SODIUM_CRYPTO_SIGN_SECRETKEYBYTES 字节
尝试从密钥对生成密钥,但出现异常: SodiumException 密钥应为 SODIUM_CRYPTO_SIGN_SECRETKEYBYTES 字节
请参阅下面的代码
if(file_exists($keypair)) {
$keypair = file_get_contents($keypair, FALSE, NULL);
dd(Keypair::fromSecretKey($keypair));
}
运行此代码后,我得到了钠异常。
SodiumException
secretkey should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes
at vendor/tightenco/solana-php-sdk/src/Keypair.php:73
69▕ static public function fromSecretKey($secretKey): Keypair
70▕ {
71▕ $secretKey = Buffer::from($secretKey)->toString();
72▕
➜ 73▕ $publicKey = sodium_crypto_sign_publickey_from_secretkey($secretKey);
74▕
75▕ return new static(
76▕ $publicKey,
77▕ $secretKey
+1 vendor frames
2 app/Console/Commands/Initializer.php:81
Tighten\SolanaPhpSdk\Keypair::fromSecretKey()
+13 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Trying to generate the secret key from the keypair and I get the exception:SodiumException secretkey should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes
See my code below
if(file_exists($keypair)) {
$keypair = file_get_contents($keypair, FALSE, NULL);
dd(Keypair::fromSecretKey($keypair));
}
After running this, I get that sodium exception.
SodiumException
secretkey should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes
at vendor/tightenco/solana-php-sdk/src/Keypair.php:73
69▕ static public function fromSecretKey($secretKey): Keypair
70▕ {
71▕ $secretKey = Buffer::from($secretKey)->toString();
72▕
➜ 73▕ $publicKey = sodium_crypto_sign_publickey_from_secretkey($secretKey);
74▕
75▕ return new static(
76▕ $publicKey,
77▕ $secretKey
+1 vendor frames
2 app/Console/Commands/Initializer.php:81
Tighten\SolanaPhpSdk\Keypair::fromSecretKey()
+13 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常简单,只需对密钥对进行 json_decode 并将数组传递给
fromSecretKey
函数即可:Quite simple, just need to json_decode the keypair and pass an array to the
fromSecretKey
function: