/** * Encrypt a secret key packet. * * @param OpenPGP_SecretKeyPacket $p Secret key packet. * @param \phpseclib\Crypt\RSA $cipher RSA cipher object. * @param OpenPGP_S2K $s2k OpenPGP String-to-key object. * @param string $iv Initial vector. */ protected function _encryptPrivateKey($p, $cipher, $s2k, $iv) { $cipher->setIV($iv); $secret = ''; foreach ($p::$secret_key_fields[$p->algorithm] as $f) { $f = $p->key[$f]; $secret .= pack('n', OpenPGP::bitlength($f)) . $f; } $secret .= hash('sha1', $secret, true); $p->encrypted_data = $iv . $cipher->encrypt($secret); $p->s2k = $s2k; $p->s2k_useage = 254; $p->symmetric_algorithm = 7; }