minigame-std
    Preparing search index...

    Function importPublicKey

    • 从 PEM 格式的字符串导入 RSA 公钥,用于加密操作。

      Parameters

      • pem: string

        PEM 格式的公钥字符串。

      • hash: SHA

        用于 OAEP 填充的哈希算法(SHA-1、SHA-256、SHA-384 或 SHA-512)。

      Returns AsyncIOResult<RSAPublicKey>

      RSA 公钥对象,包含 encrypt 方法用于加密数据。

      1.6.0

      const publicKey = (await importPublicKey(pemString, 'SHA-256')).unwrap();

      // 加密并返回 ArrayBuffer
      const encrypted = (await publicKey.encrypt('Hello, World!')).unwrap();

      // 加密并返回 Base64 字符串
      const encryptedStr = (await publicKey.encryptToString('Hello, World!')).unwrap();