Code解码接口

@param  [string] $encrypt_code  经过加密的Code码。

@return [string] code
179855
public function decrypt($encrypt_code)
    {
        if (!is_string($encrypt_code)) {
            $this->setError('参数错误');

            return false;
        }

        $queryStr                 = [];
        $queryStr['encrypt_code'] = $encrypt_code;

        $this->apitype = 'card';
        $this->module  = 'code';
        $res           = $this->_post('decrypt', $queryStr);

        return $res;
    }
199486
static public function encryptString($plaintext_string, $key_name) {
        $kms = self::getService();
        $base64_encoded_json = base64_encode($plaintext_string);
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($base64_encoded_json);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );
        return $response['ciphertext'];
    }
1165919
public function Decrypt($encryptedData) {
        $decoded = base64_decode($encryptedData, true);
        $decrypted = mcrypt_decrypt($this->encryptionType, $this->encryptionKey, $decoded, $this->encryptionMode, $this->iv);
        return $decrypted;
    }
726380
public static function getSign($url, $key, $encode = true)
    {
        parse_str($url, $arr);

        if (! $encode) {
            unset($arr['sign']);
        }

        // 首字母排序
        ksort($arr, SORT_REGULAR);

        $str = http_build_query($arr);

        // 带上私钥
        $new_str = $str . '&' . $key;

        // 签名
        $sign = openssl_encrypt($new_str, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, substr($key, 0, 16));

        return md5($sign);
    }
800020
def _tls_auth_encrypt(self, s):
        
        write_seq_num = struct.pack("!Q", self.tls_session.wcs.seq_num)
        self.tls_session.wcs.seq_num += 1
        add_data = (write_seq_num +
                    pkcs_i2osp(self.type, 1) +
                    pkcs_i2osp(self.version, 2) +
                    pkcs_i2osp(len(s), 2))
        return self.tls_session.wcs.cipher.auth_encrypt(s, add_data,
                                                        write_seq_num)
414950
public function decrypt($encrypted, $appid)
    {

		try {
			//使用BASE64对需要解密的字符串进行解码
			$ciphertext_dec = base64_decode($encrypted);
			$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
			$iv = substr($this->key, 0, 16);
			mcrypt_generic_init($module, $this->key, $iv);

			//解密
			$decrypted = mdecrypt_generic($module, $ciphertext_dec);
			mcrypt_generic_deinit($module);
			mcrypt_module_close($module);
		} catch (\Exception $e) {
			@error_log('Decrypt AES Error: ' . $e->getMessage(), 0);
			return FALSE;
		}


		try {
			//去除补位字符
			$pkc_encoder = new Pkcs7Encoder;
			$result = $pkc_encoder->decode($decrypted);
			//去除16位随机字符串,网络字节序和AppId
			if (strlen($result) < 16) {
				return "";
			}
			$content = substr($result, 16, strlen($result));
			$len_list = unpack("N", substr($content, 0, 4));
			$xml_len = $len_list[1];
			$xml_content = substr($content, 4, $xml_len);
			$from_appid = substr($content, $xml_len + 4);
		} catch (\Exception $e) {
			@error_log('Illegal Buffer: ' . $e->getMessage(), 0);
			return FALSE;
		}
		if ($from_appid != $appid) {
			@error_log('Validate Appid Error', 0);
			return FALSE;
		}
		return $xml_content;
	}
324923
def encrypt_cipher(triple_des_key)
      triple_des_key_urlencoded = ''

      key = OpenSSL::PKey::RSA.new(PUBLIC_KEY)
      encrypted_triple_des = key.public_encrypt(triple_des_key)
      encrypted_base64 = Base64.strict_encode64(encrypted_triple_des)
      triple_des_key_urlencoded = "#{CGI::escape(encrypted_base64)}decode"

      return triple_des_key_urlencoded
    end
1313432
static function Encrypt($data, $key, $encode = true)
	{
		McryptUtil::Init();
		
		$encrypted = mcrypt_encrypt(McryptUtil::$CIPHER, $key, $data, McryptUtil::$MODE, McryptUtil::$IV);
		
		return ($encode) ? base64_encode($encrypted) : $encrypted;
	}
185357
public function encrypt($original_string, $cipher_key)
    {
        $cipher_key = $this->_genKey($cipher_key);

        $ivSize = openssl_cipher_iv_length('AES-256-CBC');
        $iv = openssl_random_pseudo_bytes($ivSize);

        $cipher_text = $iv . openssl_encrypt($original_string, 'AES-256-CBC', $cipher_key, OPENSSL_RAW_DATA, $iv);

        return $this->_genHmac($cipher_text, $cipher_key) . $cipher_text;
    }
527158
public static function decrypt($encrypted_text, $key)
    {
        $md5Key = md5($key);
        
        $decrypted_text = mcrypt_decrypt(
            MCRYPT_RIJNDAEL_256, 
             $md5Key, 
             base64_decode($encrypted_text), 
             MCRYPT_MODE_CBC, 
             md5($md5Key)
        );
        
        $trimmed_decryption = rtrim($decrypted_text, "\0");
        return $trimmed_decryption;
    }
971301
function _encryptBlock($in)
    {
        list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
        $keys = $this->keys;
        $limit = 20;
        $actions = array($limit => 44, 44 => 64);
        $j = 0;

        for (;;) {
            // Mixing round.
            $r0 = (($r0 + $keys[$j++] + ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
            $r0 |= $r0 >> 16;
            $r1 = (($r1 + $keys[$j++] + ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2;
            $r1 |= $r1 >> 16;
            $r2 = (($r2 + $keys[$j++] + ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3;
            $r2 |= $r2 >> 16;
            $r3 = (($r3 + $keys[$j++] + ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5;
            $r3 |= $r3 >> 16;

            if ($j === $limit) {
                if ($limit === 64) {
                    break;
                }

                // Mashing round.
                $r0 += $keys[$r3 & 0x3F];
                $r1 += $keys[$r0 & 0x3F];
                $r2 += $keys[$r1 & 0x3F];
                $r3 += $keys[$r2 & 0x3F];
                $limit = $actions[$limit];
            }
        }

        return pack('vvvv', $r0, $r1, $r2, $r3);
    }
930806
def encrypt(api_context, request_bytes, custom_headers):
    

    key = Random.get_random_bytes(_AES_KEY_SIZE)
    iv = Random.get_random_bytes(_BLOCK_SIZE)
    _add_header_client_encryption_key(api_context, key, custom_headers)
    _add_header_client_encryption_iv(iv, custom_headers)
    request_bytes = _encrypt_request_bytes(request_bytes, key, iv)
    _add_header_client_encryption_hmac(request_bytes, key, iv, custom_headers)

    return request_bytes
659280
def encrypt_template(self, enc_key, mac_key, enc_offset):
        

        # AES-256-CBC/PKCS7Padding
        to_encrypt = self.tpl_buff[enc_offset:]
        encrypted = aes_enc(enc_key, PKCS7.pad(to_encrypt))

        # Mac the whole buffer
        to_mac = PKCS7.pad(self.tpl_buff[:enc_offset] + encrypted)
        mac = cbc_mac(mac_key, to_mac)

        return to_mac + mac
741238
public static String encryptContent(String content, String encryptType, String encryptKey,
                                        String charset) throws AlipayApiException {

        if (AES_ALG.equals(encryptType)) {

            return aesEncrypt(content, encryptKey, charset);

        } else {

            throw new AlipayApiException("当前不支持该算法类型：encrypeType=" + encryptType);
        }

    }
869234
protected function openCryptModule()
	{
		if(extension_loaded('mcrypt'))
		{
			if(is_array($this->cryptAlgorithm))
				$module=@call_user_func_array('mcrypt_module_open',$this->cryptAlgorithm);
			else
				$module=@mcrypt_module_open($this->cryptAlgorithm,'', MCRYPT_MODE_CBC,'');

			if($module===false)
				throw new CException(Yii::t('yii','Failed to initialize the mcrypt module.'));

			return $module;
		}
		else
			throw new CException(Yii::t('yii','CSecurityManager requires PHP mcrypt extension to be loaded in order to use data encryption feature.'));
	}
1302751
public function decrypt($encrypted, $appId)
    {
        try {
            //使用BASE64对需要解密的字符串进行解码
            $key        = $this->getAESKey();
            $ciphertext = base64_decode($encrypted, true);
            $iv         = substr($key, 0, 16);

            $decrypted = openssl_decrypt($ciphertext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING, $iv);
        } catch (Exception $e) {
            return [ErrorCode::$DecryptAESError, null];
        }

        try {
            $result = $this->decode($decrypted);

            if (strlen($result) < 16) {
                return '';
            }

            $content   = substr($result, 16, strlen($result));
            $listLen   = unpack('N', substr($content, 0, 4));
            $xmlLen    = $listLen[1];
            $xml       = substr($content, 4, $xmlLen);
            $fromAppId = trim(substr($content, $xmlLen + 4));
        } catch (Exception $e) {
            //print $e;
            return [ErrorCode::$IllegalBuffer, null];
        }
        if ($fromAppId !== $appId) {
            return [ErrorCode::$ValidateAppidError, null];
        }

        $dataSet = json_decode($xml, true);
        if ($dataSet && (JSON_ERROR_NONE === json_last_error())) {
            // For mini-program JSON formats.
            // Convert to XML if the given string can be decode into a data array.
            $xml = XML::build($dataSet);
        }

        return [ErrorCode::$OK, $xml];
    }
1202452
def encrypt(self, key, iv="", cek="", **kwargs):
        

        _msg = as_bytes(self.msg)
        if "zip" in self:
            if self["zip"] == "DEF":
                _msg = zlib.compress(_msg)
            else:
                raise ParameterError("Zip has unknown value: %s" % self["zip"])

        kwarg_cek = cek or None

        _enc = self["enc"]
        iv = self._generate_iv(_enc, iv)
        cek = self._generate_key(_enc, cek)
        self["cek"] = cek

        logger.debug("cek: %s, iv: %s" % ([c for c in cek], [c for c in iv]))

        _encrypt = RSAEncrypter(self.with_digest).encrypt

        _alg = self["alg"]
        if kwarg_cek:
            jwe_enc_key = ''
        elif _alg == "RSA-OAEP":
            jwe_enc_key = _encrypt(cek, key, 'pkcs1_oaep_padding')
        elif _alg == "RSA-OAEP-256":
            jwe_enc_key = _encrypt(cek, key, 'pkcs1_oaep_256_padding')
        elif _alg == "RSA1_5":
            jwe_enc_key = _encrypt(cek, key)
        else:
            raise NotSupportedAlgorithm(_alg)

        jwe = JWEnc(**self.headers())

        try:
            _auth_data = kwargs['auth_data']
        except KeyError:
            _auth_data = jwe.b64_encode_header()

        ctxt, tag, key = self.enc_setup(_enc, _msg, key=cek, iv=iv,
                                        auth_data=_auth_data)
        return jwe.pack(parts=[jwe_enc_key, iv, ctxt, tag])