OpenSSL的"密封"在C(或通过壳) [英] OpenSSL "Seal" in C (or via shell)

查看:134
本文介绍了OpenSSL的"密封"在C(或通过壳)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作移植一些PHP code到C,接触网络的API。

I'm working on porting some PHP code to C, that contacts a web API.

我遇到的问题是,PHP code使用功能 openssl_seal(),但我似乎无法找到任何方式做甚至通过的OpenSSL 在C同样的事情在调用系统()

The issue I've come across is that the PHP code uses the function openssl_seal(), but I can't seem to find any way to do the same thing in C or even via openssl in a call to system().

从上 openssl_seal PHP手册()

INT openssl_seal(字符串$数据,
  串放; $ sealed_data,数组
  &安培; $ env_keys,数组$ pub_key_ids)

int openssl_seal ( string $data , string &$sealed_data , array &$env_keys , array $pub_key_ids )

openssl_seal()密封(加密)的数据
  通过使用RC4用随机生成
  密钥。关键是用加密
  每个相关联的公共密钥的
  在pub_key_ids标识符
  并且每个加密密钥在返回
  env_keys。这意味着可以
  封发送的数据到多个
  收件人(提供的一个已获得
  他们的公共密钥)。每个收件人
  必须接收两个密封数据和
  被加密的信封关键
  与接收方的公钥。

openssl_seal() seals (encrypts) data by using RC4 with a randomly generated secret key. The key is encrypted with each of the public keys associated with the identifiers in pub_key_ids and each encrypted key is returned in env_keys . This means that one can send sealed data to multiple recipients (provided one has obtained their public keys). Each recipient must receive both the sealed data and the envelope key that was encrypted with the recipient's public key.

什么是实现这一目标的最佳方式是什么?我真的preFER的的每一次调出一个PHP脚本,原因是显而易见的。

What would be the best way to implement this? I'd really prefer not to call out to a PHP script every time, for obvious reasons.

推荐答案

您是EVP(信封加密)之后的C接口OpenSSL库的一部分:

You are after the EVP ("Envelope Encryption") part of the C interface to the OpenSSL library:

#include <openssl/evp.h>

int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
                 unsigned char **ek, int *ekl, unsigned char *iv,
                 EVP_PKEY **pubk, int npubk);
int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
        int *outl, unsigned char *in, int inl);
int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
        int *outl);

(在这种情况下,因为你要为RC4用PHP code兼容性,你会使用 EVP_rc4()键入参数 EVP_SealInit())。

这篇关于OpenSSL的&QUOT;密封&QUOT;在C(或通过壳)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆