跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Go 编程语言] golang 怎么实现 rsa 加解密

发表于

一般是公钥加密,私钥解密。 但是这份代码,需要私钥加密,公钥解密。

下边是 php 代码,公钥解密

function public_key_decrypt($data, $public_key)
{
    $public_key = '-----BEGIN PUBLIC KEY-----' . "\n" . $public_key . "\n" . '-----END PUBLIC KEY-----';
    $data = base64_decode($data);
    $pu_key = openssl_pkey_get_public($public_key);
    $crypto = '';
    foreach (str_split($data, 128) as $chunk) {
        openssl_public_decrypt($chunk, $decryptData, $pu_key);
        $crypto .= $decryptData;
    }

    return $crypto;
}

用 chatgpt 转化为 golang 的时候代码有问题。 想问下该怎么处理。

func (t *TopPayService) rsaPublicDecrypt(publicKey *rsa.PublicKey, encryptedData []byte) ([]byte, error) { // 使用 RSA OAEP 解密 decryptedData, err := rsa.DecryptOAEP( sha256.New(), // 使用 SHA-256 作为哈希函数 rand.Reader, // 随机数生成器 publicKey, // 公钥 encryptedData, // 加密的数据 nil, // 可选的 label ,默认为 nil ) if err != nil { return nil, err } return decryptedData, nil }

Featured Replies

No posts to show

创建帐户或登录来提出意见

Account

导航

搜索

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.