task: encode RSA data sync to server

CR: sonhh (fake)
This commit is contained in:
2021-09-09 17:08:56 +07:00
parent a27bf65303
commit 66357b25d5
2 changed files with 47 additions and 20 deletions

View File

@@ -231,4 +231,11 @@ class common extends \yii\db\ActiveRecord {
];
}
public static function rsaEncode($text) {
$publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCXB8c44cboYsGG6IzISqxf8W7q3AN0mGmekDYpBWpz9udif+jwK6h7NuOZvFDeB/32TVrtvaGDmExCeBerpcoOvGh4eUXyke2lSLzrg7pc/wD0KproEGoAAFDB0Pr5bZhg6ELp3Sk++0MPyxH6u1pgtHDxEnMwXV8cxw/rSCM+wIDAQAB";
$publicKey = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($publicKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
openssl_public_encrypt($text, $encrypted, $publicKey, OPENSSL_PKCS1_PADDING);
return base64_encode($encrypted);
}
}