SodiumException 密钥应该是 SODIUM_CRYPTO_SIGN_SECRETKEYBYTES 字节

发布于 2025-01-11 18:05:28 字数 1028 浏览 3 评论 0原文

尝试从密钥对生成密钥,但出现异常: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2025-01-18 18:05:28

非常简单,只需对密钥对进行 json_decode 并将数组传递给 fromSecretKey 函数即可:

  $keypair = file_get_contents($keypair, FALSE, NULL);

  dd(Keypair::fromSecretKey(json_decode($keypair)));

Quite simple, just need to json_decode the keypair and pass an array to the fromSecretKey function:

  $keypair = file_get_contents($keypair, FALSE, NULL);

  dd(Keypair::fromSecretKey(json_decode($keypair)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文