当前位置: 首页>>代码示例>>C++>>正文


C++ EVP_rc4函数代码示例

本文整理汇总了C++中EVP_rc4函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_rc4函数的具体用法?C++ EVP_rc4怎么用?C++ EVP_rc4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EVP_rc4函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EVP_CIPHER_CTX_init

/******************************************************************************
 Two way hashing: AES, DES, BlowFish, RC4
 ******************************************************************************/
void Encryption::EncryptionInit() {
    unsigned char key[EVP_MAX_KEY_LENGTH];
    unsigned char iv[EVP_MAX_IV_LENGTH] = "Ben";
    EVP_CIPHER_CTX_init(&ectx);
    EVP_CIPHER_CTX_init(&dctx);
    /* 8 bytes to salt the key_data during key generation. This is an example of
     compiled in salt. We just read the bit pattern created by these two 4 byte
     integers on the stack as 64 bits of contigous salt material -
     ofcourse this only works if sizeof(int) >= 4 */
    unsigned int salt[] = { 12345, 54321 };
    int i, nrounds = 5;
    switch (EncryptionType) {
    case 0:
        //No Encryption Mode
        break;
    case 1:
        i = EVP_BytesToKey(EVP_aes_128_cfb(), EVP_sha1(),
                           (unsigned char *) &salt, (unsigned char *) Password, strlen(
                               Password), nrounds, key, iv);
        EVP_EncryptInit_ex(&ectx, EVP_aes_128_cfb(), NULL,
                           (unsigned char*) key, (unsigned char*) &iv);
        EVP_DecryptInit_ex(&dctx, EVP_aes_128_cfb(), NULL,
                           (unsigned char*) key, (unsigned char*) &iv);
        break;
    case 2:
        i = EVP_BytesToKey(EVP_des_ede_cfb(), EVP_sha1(),
                           (unsigned char *) &salt, (unsigned char *) Password, strlen(
                               Password), nrounds, key, iv);
        EVP_EncryptInit_ex(&ectx, EVP_des_ede_cfb(), NULL,
                           (unsigned char*) key, (unsigned char*) &iv);
        EVP_DecryptInit_ex(&dctx, EVP_des_ede_cfb(), NULL,
                           (unsigned char*) key, (unsigned char*) &iv);
        break;
    case 3:
        i = EVP_BytesToKey(EVP_rc4(), EVP_sha1(), (unsigned char *) &salt,
                           (unsigned char *) Password, strlen(Password), nrounds, key, iv);
        EVP_EncryptInit_ex(&ectx, EVP_rc4(), NULL, (unsigned char*) key,
                           (unsigned char*) &iv);
        EVP_DecryptInit_ex(&dctx, EVP_rc4(), NULL, (unsigned char*) key,
                           (unsigned char*) &iv);
        break;
    case 4:
        i = EVP_BytesToKey(EVP_bf_cfb(), EVP_sha1(), (unsigned char *) &salt,
                           (unsigned char *) Password, strlen(Password), nrounds, key, iv);
        EVP_EncryptInit_ex(&ectx, EVP_bf_cfb(), NULL, (unsigned char*) key,
                           (unsigned char*) &iv);
        EVP_DecryptInit_ex(&dctx, EVP_bf_cfb(), NULL, (unsigned char*) key,
                           (unsigned char*) &iv);
        break;
    }
    return;
}
开发者ID:Benneel,项目名称:Networking,代码行数:55,代码来源:Encryption.cpp

示例2: enc_ctx_init

void enc_ctx_init(EVP_CIPHER_CTX *ctx, const char *pass, int enc) {
    unsigned char key[EVP_MAX_KEY_LENGTH];
    unsigned char iv[EVP_MAX_IV_LENGTH];
    int key_len = EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, (unsigned char*) pass, 
            strlen(pass), 1, key, iv);
    EVP_CIPHER_CTX_init(ctx);
    EVP_CipherInit_ex(ctx, EVP_rc4(), NULL, NULL, NULL, enc);
    if (!EVP_CIPHER_CTX_set_key_length(ctx, key_len)) {
        LOGE("Invalid key length: %d", key_len);
        EVP_CIPHER_CTX_cleanup(ctx);
        exit(EXIT_FAILURE);
    }
    EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, enc);
}
开发者ID:AmVPN,项目名称:proxydroid,代码行数:14,代码来源:encrypt.c

示例3: EVP_CIPHER_CTX_init

SARC4::SARC4(uint8* seed, uint8 len)
{
    EVP_CIPHER_CTX_init(&m_ctx);
    EVP_EncryptInit_ex(&m_ctx, EVP_rc4(), nullptr, nullptr, nullptr);
    EVP_CIPHER_CTX_set_key_length(&m_ctx, len);
    EVP_EncryptInit_ex(&m_ctx, nullptr, nullptr, seed, nullptr);
}
开发者ID:AwkwardDev,项目名称:mangos-d3,代码行数:7,代码来源:SARC4.cpp

示例4: m_ctx

ARC4::ARC4(uint8 *seed, uint8 len) : m_ctx()
{
    m_ctx = EVP_CIPHER_CTX_new();
    EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
    EVP_CIPHER_CTX_set_key_length(m_ctx, len);
    EVP_EncryptInit_ex(m_ctx, NULL, NULL, seed, NULL);
}
开发者ID:billy1arm,项目名称:serverZero,代码行数:7,代码来源:ARC4.cpp

示例5: SSL_library_init

EXPORT_C int SSL_library_init(void)
	{
//#ifdef EMULATOR	
//	InitSSLWsdVar();	
//#endif	
#ifndef OPENSSL_NO_DES
	EVP_add_cipher(EVP_des_cbc());
	EVP_add_cipher(EVP_des_ede3_cbc());
#endif
#ifndef OPENSSL_NO_IDEA
	EVP_add_cipher(EVP_idea_cbc());
#endif
#ifndef OPENSSL_NO_RC4
	EVP_add_cipher(EVP_rc4());
#endif  
#ifndef OPENSSL_NO_RC2
	EVP_add_cipher(EVP_rc2_cbc());
#endif
#ifndef OPENSSL_NO_AES
	EVP_add_cipher(EVP_aes_128_cbc());
	EVP_add_cipher(EVP_aes_192_cbc());
	EVP_add_cipher(EVP_aes_256_cbc());
#endif
#ifndef OPENSSL_NO_MD2
	EVP_add_digest(EVP_md2());
#endif
#ifndef OPENSSL_NO_MD5
	EVP_add_digest(EVP_md5());
	EVP_add_digest_alias(SN_md5,"ssl2-md5");
	EVP_add_digest_alias(SN_md5,"ssl3-md5");
#endif
#ifndef OPENSSL_NO_SHA
	EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
	EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
	EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
#endif
#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_DSA)
	EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
	EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
	EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
	EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
#endif
#ifndef OPENSSL_NO_ECDSA
	EVP_add_digest(EVP_ecdsa());
#endif
	/* If you want support for phased out ciphers, add the following */
#if 0
	EVP_add_digest(EVP_sha());
	EVP_add_digest(EVP_dss());
#endif
#ifndef OPENSSL_NO_COMP
	/* This will initialise the built-in compression algorithms.
	   The value returned is a STACK_OF(SSL_COMP), but that can
	   be discarded safely */
	(void)SSL_COMP_get_compression_methods();
#endif
	/* initialize cipher/digest methods table */
	ssl_load_ciphers();
	return(1);
	}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:60,代码来源:ssl_algs.c

示例6: encrypt

int encrypt(unsigned char * plaintext, int plaintext_len, unsigned char * key, unsigned char * iv, unsigned char * ciphertext) {
	EVP_CIPHER_CTX *ctx;
	int len;
	int ciphertext_len;

	// init context
	if(!(ctx = EVP_CIPHER_CTX_new())){
       		 handle_errors();
	}
	// init encryption operation
	if(1 != EVP_EncryptInit_ex(ctx, EVP_rc4(), NULL, key, iv)){
		handle_errors();
	}
	// obtain encrypted output
	if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len)){
		handle_errors();
		ciphertext_len = len; 
	}
	ciphertext_len=len;
	// finalize 
	if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)){
		handle_errors();
		ciphertext_len += len;
	}
	ciphertext_len += len;
	EVP_CIPHER_CTX_free(ctx);
	return ciphertext_len;

}
开发者ID:histind,项目名称:SecureRT,代码行数:29,代码来源:rttask_rc4.c

示例7: m_ctx

ARC4::ARC4(uint8* seed, uint32 len) : m_ctx(EVP_CIPHER_CTX_new())
{
    EVP_CIPHER_CTX_init(m_ctx);
    EVP_EncryptInit_ex(m_ctx, EVP_rc4(), nullptr, nullptr, nullptr);
    EVP_CIPHER_CTX_set_key_length(m_ctx, len);
    EVP_EncryptInit_ex(m_ctx, nullptr, nullptr, seed, nullptr);
}
开发者ID:Carbenium,项目名称:TrinityCore,代码行数:7,代码来源:ARC4.cpp

示例8: EVP_CIPHER_CTX_init

ARC4::ARC4(uint8 *seed, uint8 len)
{
    EVP_CIPHER_CTX_init(&m_ctx);
    EVP_EncryptInit_ex(&m_ctx, EVP_rc4(), NULL, NULL, NULL);
    EVP_CIPHER_CTX_set_key_length(&m_ctx, len);
    EVP_EncryptInit_ex(&m_ctx, NULL, NULL, seed, NULL);
}
开发者ID:1024wow,项目名称:TrinityCore,代码行数:7,代码来源:ARC4.cpp

示例9: aead_rc4_sha1_tls_get_rc4_state

static int aead_rc4_sha1_tls_get_rc4_state(const EVP_AEAD_CTX *ctx,
                                           const RC4_KEY **out_key) {
  const AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX*) ctx->aead_state;
  if (EVP_CIPHER_CTX_cipher(&tls_ctx->cipher_ctx) != EVP_rc4()) {
    return 0;
  }

  *out_key = (const RC4_KEY*) tls_ctx->cipher_ctx.cipher_data;
  return 1;
}
开发者ID:gotomypc,项目名称:tiny-webrtc-gw,代码行数:10,代码来源:e_tls.c

示例10: SSL_library_init

int
SSL_library_init(void)
{

#ifndef OPENSSL_NO_DES
	EVP_add_cipher(EVP_des_cbc());
	EVP_add_cipher(EVP_des_ede3_cbc());
#endif
#ifndef OPENSSL_NO_IDEA
	EVP_add_cipher(EVP_idea_cbc());
#endif
#ifndef OPENSSL_NO_RC4
	EVP_add_cipher(EVP_rc4());
#if !defined(OPENSSL_NO_MD5) && (defined(__x86_64) || defined(__x86_64__))
	EVP_add_cipher(EVP_rc4_hmac_md5());
#endif
#endif  
#ifndef OPENSSL_NO_RC2
	EVP_add_cipher(EVP_rc2_cbc());
	/* Not actually used for SSL/TLS but this makes PKCS#12 work
	 * if an application only calls SSL_library_init().
	 */
	EVP_add_cipher(EVP_rc2_40_cbc());
#endif
	EVP_add_cipher(EVP_aes_128_cbc());
	EVP_add_cipher(EVP_aes_192_cbc());
	EVP_add_cipher(EVP_aes_256_cbc());
	EVP_add_cipher(EVP_aes_128_gcm());
	EVP_add_cipher(EVP_aes_256_gcm());
	EVP_add_cipher(EVP_aes_128_cbc_hmac_sha1());
	EVP_add_cipher(EVP_aes_256_cbc_hmac_sha1());
#ifndef OPENSSL_NO_CAMELLIA
	EVP_add_cipher(EVP_camellia_128_cbc());
	EVP_add_cipher(EVP_camellia_256_cbc());
#endif

	EVP_add_digest(EVP_md5());
	EVP_add_digest_alias(SN_md5, "ssl2-md5");
	EVP_add_digest_alias(SN_md5, "ssl3-md5");
	EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
	EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
	EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
	EVP_add_digest(EVP_sha224());
	EVP_add_digest(EVP_sha256());
	EVP_add_digest(EVP_sha384());
	EVP_add_digest(EVP_sha512());
	EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
	EVP_add_digest_alias(SN_dsaWithSHA1, SN_dsaWithSHA1_2);
	EVP_add_digest_alias(SN_dsaWithSHA1, "DSS1");
	EVP_add_digest_alias(SN_dsaWithSHA1, "dss1");
	EVP_add_digest(EVP_ecdsa());
	/* initialize cipher/digest methods table */
	ssl_load_ciphers();
	return (1);
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:55,代码来源:ssl_algs.c

示例11: EVP_CIPHER_do_all_sorted

void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
                                               const char *name,
                                               const char *unused, void *arg),
                              void *arg) {
  callback(EVP_aes_128_cbc(), "AES-128-CBC", NULL, arg);
  callback(EVP_aes_128_ctr(), "AES-128-CTR", NULL, arg);
  callback(EVP_aes_128_ecb(), "AES-128-ECB", NULL, arg);
  callback(EVP_aes_128_ofb(), "AES-128-OFB", NULL, arg);
  callback(EVP_aes_256_cbc(), "AES-256-CBC", NULL, arg);
  callback(EVP_aes_256_ctr(), "AES-256-CTR", NULL, arg);
  callback(EVP_aes_256_ecb(), "AES-256-ECB", NULL, arg);
  callback(EVP_aes_256_ofb(), "AES-256-OFB", NULL, arg);
  callback(EVP_aes_256_xts(), "AES-256-XTS", NULL, arg);
  callback(EVP_des_cbc(), "DES-CBC", NULL, arg);
  callback(EVP_des_ecb(), "DES-ECB", NULL, arg);
  callback(EVP_des_ede(), "DES-EDE", NULL, arg);
  callback(EVP_des_ede_cbc(), "DES-EDE-CBC", NULL, arg);
  callback(EVP_des_ede3_cbc(), "DES-EDE3-CBC", NULL, arg);
  callback(EVP_rc2_cbc(), "RC2-CBC", NULL, arg);
  callback(EVP_rc4(), "RC4", NULL, arg);

  // OpenSSL returns everything twice, the second time in lower case.
  callback(EVP_aes_128_cbc(), "aes-128-cbc", NULL, arg);
  callback(EVP_aes_128_ctr(), "aes-128-ctr", NULL, arg);
  callback(EVP_aes_128_ecb(), "aes-128-ecb", NULL, arg);
  callback(EVP_aes_128_ofb(), "aes-128-ofb", NULL, arg);
  callback(EVP_aes_256_cbc(), "aes-256-cbc", NULL, arg);
  callback(EVP_aes_256_ctr(), "aes-256-ctr", NULL, arg);
  callback(EVP_aes_256_ecb(), "aes-256-ecb", NULL, arg);
  callback(EVP_aes_256_ofb(), "aes-256-ofb", NULL, arg);
  callback(EVP_aes_256_xts(), "aes-256-xts", NULL, arg);
  callback(EVP_des_cbc(), "des-cbc", NULL, arg);
  callback(EVP_des_ecb(), "des-ecb", NULL, arg);
  callback(EVP_des_ede(), "des-ede", NULL, arg);
  callback(EVP_des_ede_cbc(), "des-ede-cbc", NULL, arg);
  callback(EVP_des_ede3_cbc(), "des-ede3-cbc", NULL, arg);
  callback(EVP_rc2_cbc(), "rc2-cbc", NULL, arg);
  callback(EVP_rc4(), "rc4", NULL, arg);
}
开发者ID:0x64616E69656C,项目名称:boringssl,代码行数:39,代码来源:evp_do_all.c

示例12: LUA_FUNCTION

/* {{{ proto opendata openssl_open(string data, string ekey, mixed privkey, [, cipher enc|string md_alg=RC4])
   Opens data */
LUA_API LUA_FUNCTION(openssl_open)
{
    size_t data_len, ekey_len;
    const char * data = luaL_checklstring(L, 1, &data_len);
    const char * ekey = luaL_checklstring(L, 2, &ekey_len);
    EVP_PKEY *pkey =  CHECK_OBJECT(3,EVP_PKEY, "openssl.evp_pkey");
    int top = lua_gettop(L);

    int len1, len2 = 0;
    unsigned char *buf;

    EVP_CIPHER_CTX ctx;
    const EVP_CIPHER *cipher = NULL;

    if(top>3) {
        if(lua_isstring(L,4))
            cipher = EVP_get_cipherbyname(lua_tostring(L,4));
        else if(lua_isuserdata(L,4))
            cipher = CHECK_OBJECT(4,EVP_CIPHER,"openssl.evp_cipher");
        else
            luaL_error(L, "#4 argument must be nil, string, or openssl.evp_cipher object");
    }
    if(!cipher)
        cipher = EVP_rc4();

    len1 = data_len + 1;
    buf = malloc(len1);

    if (EVP_OpenInit(&ctx, cipher, (unsigned char *)ekey, ekey_len, NULL, pkey) && EVP_OpenUpdate(&ctx, buf, &len1, (unsigned char *)data, data_len))
    {
        len2 = data_len - len1;
        if (!EVP_OpenFinal(&ctx, buf + len1, &len2) || (len1 + len2 == 0))
        {
            luaL_error(L,"EVP_OpenFinal() failed.");
            free(buf);
            return 0;
        }
    }
    else
    {
        luaL_error(L,"EVP_OpenInit() failed.");
        free(buf);
        return 0;
    }

    buf[len1 + len2] = '\0';
    lua_pushlstring(L, (const char*)buf, len1 + len2);
    free(buf);
    return 1;
}
开发者ID:unitfloat,项目名称:lua-openssl,代码行数:52,代码来源:openssl.c

示例13: SSL_library_init

int SSL_library_init(void)
	{
#ifndef NO_DES
	EVP_add_cipher(EVP_des_cbc());
	EVP_add_cipher(EVP_des_ede3_cbc());
#endif
#ifndef NO_IDEA
	EVP_add_cipher(EVP_idea_cbc());
#endif
#ifndef NO_RC4
	EVP_add_cipher(EVP_rc4());
#endif  
#ifndef NO_RC2
	EVP_add_cipher(EVP_rc2_cbc());
#endif  

#ifndef NO_MD2
	EVP_add_digest(EVP_md2());
#endif
#ifndef NO_MD5
	EVP_add_digest(EVP_md5());
	EVP_add_digest_alias(SN_md5,"ssl2-md5");
	EVP_add_digest_alias(SN_md5,"ssl3-md5");
#endif
#ifndef NO_SHA
	EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
	EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
	EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
#endif
#if !defined(NO_SHA) && !defined(NO_DSA)
	EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
	EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
	EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
	EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
#endif

	/* If you want support for phased out ciphers, add the following */
#if 0
	EVP_add_digest(EVP_sha());
	EVP_add_digest(EVP_dss());
#endif
	return(1);
	}
开发者ID:aosm,项目名称:OpenSSL096,代码行数:43,代码来源:ssl_algs.c

示例14: PKCS12_PBE_add

void PKCS12_PBE_add(void)
{
#ifndef OPENSSL_NO_RC4
EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(),
							 PKCS12_PBE_keyivgen);
EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(),
							 PKCS12_PBE_keyivgen);
#endif
#ifndef OPENSSL_NO_DES
EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
		 	EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC, 
			EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
#endif
#ifndef OPENSSL_NO_RC2
EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
					EVP_sha1(), PKCS12_PBE_keyivgen);
EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
					EVP_sha1(), PKCS12_PBE_keyivgen);
#endif
}
开发者ID:FelipeFernandes1988,项目名称:Alice-1121-Modem,代码行数:21,代码来源:p12_crpt.c

示例15: EVP_rc4

const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
  if (OPENSSL_strcasecmp(name, "rc4") == 0) {
    return EVP_rc4();
  } else if (OPENSSL_strcasecmp(name, "des-cbc") == 0) {
    return EVP_des_cbc();
  } else if (OPENSSL_strcasecmp(name, "des-ede3-cbc") == 0 ||
             OPENSSL_strcasecmp(name, "3des") == 0) {
    return EVP_des_ede3_cbc();
  } else if (OPENSSL_strcasecmp(name, "aes-128-cbc") == 0) {
    return EVP_aes_128_cbc();
  } else if (OPENSSL_strcasecmp(name, "aes-256-cbc") == 0) {
    return EVP_aes_256_cbc();
  } else if (OPENSSL_strcasecmp(name, "aes-128-ctr") == 0) {
    return EVP_aes_128_ctr();
  } else if (OPENSSL_strcasecmp(name, "aes-256-ctr") == 0) {
    return EVP_aes_256_ctr();
  } else if (OPENSSL_strcasecmp(name, "aes-128-ecb") == 0) {
    return EVP_aes_128_ecb();
  } else if (OPENSSL_strcasecmp(name, "aes-256-ecb") == 0) {
    return EVP_aes_256_ecb();
  }

  return NULL;
}
开发者ID:AadityaDev,项目名称:AadityaDev.github.io,代码行数:24,代码来源:cipher_extra.c


注:本文中的EVP_rc4函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。