安全与风控

EasyWeChat 4.0.7+

获取 RSA 公钥

  1. $result = $app->security->getPublicKey();
  2. // 存成文件
  3. file_put_contents('./public.pem', $result);

将会得到 PKCS#1 格式密钥:

  1. -----BEGIN RSA PUBLIC KEY-----
  2. MIIBCgKCAQEArT82k67xybiJS9AD8nNAeuDYdrtCRaxkS6cgs8L9h83eqlDTlrdw
  3. zBVSv5V4imTq/URbXn4K0V/KJ1TwDrqOI8hamGB0fvU13WW1NcJuv41RnJVua0QA
  4. lS3tS1JzOZpMS9BEGeFvyFF/epbi/m9+2kUWG94FccArNnBtBqqvFncXgQsm98JB
  5. 3a62NbS1ePP/hMI7Kkz+JNMyYsWkrOUFDCXAbSZkWBJekY4nGZtK1erqGRve8Jbx
  6. TWirAm/s08rUrjOuZFA21/EI2nea3DidJMTVnXVPY2qcAjF+595shwUKyTjKB8v1
  7. REPB3hPF1Z75O6LwuLfyPiCrCTmVoyfqjwIDAQAB
  8. -----END RSA PUBLIC KEY-----

使用 OpenSSL 转换 PKCS#1 为 PKCS#8 格式密钥:

  1. openssl rsa -RSAPublicKey_in -in public.pem -out public.pem

PKCS#8 格式密钥:

  1. -----BEGIN PUBLIC KEY-----
  2. MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArT82k67xybiJS9AD8nNA
  3. euDYdrtCRaxkS6cgs8L9h83eqlDTlrdwzBVSv5V4imTq/URbXn4K0V/KJ1TwDrqO
  4. I8hamGB0fvU13WW1NcJuv41RnJVua0QAlS3tS1JzOZpMS9BEGeFvyFF/epbi/m9+
  5. lkUWG94FccArNnBtBqqvFncXgQsm98JB3a42NbS1ePP/hMI7Kkz+JNMyYsWkrOUF
  6. DCXAbSZkWBJekY4nGZtK1erqGRve8JbxTWirAm/s08rUrjOuZFA21/EI2nea3Did
  7. JMTVnXVPY2qcAjF+595shwUKyTjKB8v1REPB3hPF1Z75O6LwuLfyPiCrCTmVoyfq
  8. jwIDAQAB
  9. -----END PUBLIC KEY-----