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 Promise<RSAPublicKey>

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

      const publicKey = await importPublicKey(pemString, 'SHA-256');
      const encrypted = await publicKey.encrypt('Hello, World!');
      console.log(encrypted); // Base64 编码的加密数据