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


C++ EVP_PKEY_type函数代码示例

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


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

示例1: EVP_PKEY_set_alias_type

int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type)
{
    if (pkey->type == type) {
        return 1; /* it already is that type */
    }

    /*
     * The application is requesting to alias this to a different pkey type,
     * but not one that resolves to the base type.
     */
    if (EVP_PKEY_type(type) != EVP_PKEY_base_id(pkey)) {
        EVPerr(EVP_F_EVP_PKEY_SET_ALIAS_TYPE, EVP_R_UNSUPPORTED_ALGORITHM);
        return 0;
    }

    pkey->type = type;
    return 1;
}
开发者ID:EiffelSoftware,项目名称:EiffelStudio,代码行数:18,代码来源:p_lib.c

示例2: ossl_ec_new

VALUE ossl_ec_new(EVP_PKEY *pkey)
{
    VALUE obj;

    if (!pkey) {
	obj = ec_instance(cEC, EC_KEY_new());
    } else {
	if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) {
	    ossl_raise(rb_eTypeError, "Not a EC key!");
	}
	WrapPKey(cEC, obj, pkey);
    }
    if (obj == Qfalse) {
	ossl_raise(eECError, NULL);
    }

    return obj;
}
开发者ID:fi8on,项目名称:ruby,代码行数:18,代码来源:ossl_pkey_ec.c

示例3: switch

QString pki_key::getTypeString()
{
	QString type;
	switch (EVP_PKEY_type(key->type)) {
		case EVP_PKEY_RSA:
			type = "RSA";
			break;
		case EVP_PKEY_DSA:
			type = "DSA";
			break;
		case EVP_PKEY_EC:
			type = "EC";
			break;
		default:
			type = "---";
	}
	return type;
}
开发者ID:jbfavre,项目名称:xca,代码行数:18,代码来源:pki_key.cpp

示例4: pkcs8

/* static */
Key* Key::ImportKey(const AuthorizationSet& key_description, keymaster_key_format_t key_format,
                    const uint8_t* key_data, size_t key_data_length, const Logger& logger,
                    keymaster_error_t* error) {
    *error = KM_ERROR_OK;

    if (key_data == NULL || key_data_length <= 0) {
        *error = KM_ERROR_INVALID_KEY_BLOB;
        return NULL;
    }

    if (key_format != KM_KEY_FORMAT_PKCS8) {
        *error = KM_ERROR_UNSUPPORTED_KEY_FORMAT;
        return NULL;
    }

    UniquePtr<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_Delete> pkcs8(
        d2i_PKCS8_PRIV_KEY_INFO(NULL, &key_data, key_data_length));
    if (pkcs8.get() == NULL) {
        *error = KM_ERROR_MEMORY_ALLOCATION_FAILED;
        return NULL;
    }

    UniquePtr<EVP_PKEY, EVP_PKEY_Delete> pkey(EVP_PKCS82PKEY(pkcs8.get()));
    if (pkey.get() == NULL) {
        *error = KM_ERROR_INVALID_KEY_BLOB;
        return NULL;
    }

    UniquePtr<Key> key;
    switch (EVP_PKEY_type(pkey->type)) {
    case EVP_PKEY_RSA:
        return RsaKey::ImportKey(key_description, pkey.get(), logger, error);
    case EVP_PKEY_DSA:
        return DsaKey::ImportKey(key_description, pkey.get(), logger, error);
    case EVP_PKEY_EC:
        return EcdsaKey::ImportKey(key_description, pkey.get(), logger, error);
    default:
        *error = KM_ERROR_UNSUPPORTED_ALGORITHM;
        return NULL;
    }

    *error = KM_ERROR_UNIMPLEMENTED;
    return NULL;
}
开发者ID:PDi-Communication-Systems-Inc,项目名称:lollipop_system_keymaster,代码行数:45,代码来源:key.cpp

示例5: ossl_dh_new

VALUE
ossl_dh_new(EVP_PKEY *pkey)
{
    VALUE obj;

    if (!pkey) {
	obj = dh_instance(cDH, DH_new());
    } else {
	if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) {
	    ossl_raise(rb_eTypeError, "Not a DH key!");
	}
	WrapPKey(cDH, obj, pkey);
    }
    if (obj == Qfalse) {
	ossl_raise(eDHError, NULL);
    }

    return obj;
}
开发者ID:0x00evil,项目名称:ruby,代码行数:19,代码来源:ossl_pkey_dh.c

示例6: load_and_print_pubkey

int load_and_print_pubkey(FILE* pemFile, int version) {
  assert(pemFile);

  EVP_PKEY* pubkey = PEM_read_PUBKEY(pemFile, NULL, NULL, NULL);
  if (!pubkey) {
    fprintf(stderr, "error: PEM_read_PUBKEY() failed.\n");
    return 1;
  }

  if (EVP_PKEY_type(pubkey->type) != EVP_PKEY_EC) {
    fprintf(stderr, "error: PEM does not contain an EC key.\n");
    EVP_PKEY_free(pubkey);
    return 1;
  }
  
  int result = extract_and_print_eckey(pubkey, version);
  EVP_PKEY_free(pubkey);
  return result;
}
开发者ID:0963682490,项目名称:omaha,代码行数:19,代码来源:eckeytool.c

示例7: PKI_sign_RSA

SEXP PKI_sign_RSA(SEXP what, SEXP sMD, SEXP sKey) {
    SEXP res;
    int md = asInteger(sMD), type;
    EVP_PKEY *key;
    RSA *rsa;
    unsigned int siglen = sizeof(buf);
  switch (md) {
    case PKI_MD5:
      type = NID_md5;
      break;
    case PKI_SHA1:
      type = NID_sha1;
      break;
    case PKI_SHA256:
      type = NID_sha256;
      break;
    default:
      Rf_error("unsupported hash type");
  }
    if (TYPEOF(what) != RAWSXP ||
	(md == PKI_MD5 && LENGTH(what) != MD5_DIGEST_LENGTH) ||
	(md == PKI_SHA1 && LENGTH(what) != SHA_DIGEST_LENGTH) ||
  (md == PKI_SHA256 && LENGTH(what) != SHA256_DIGEST_LENGTH))
	Rf_error("invalid hash");
    if (!inherits(sKey, "private.key"))
	Rf_error("key must be RSA private key");
    key = (EVP_PKEY*) R_ExternalPtrAddr(sKey);
    if (!key)
	Rf_error("NULL key");
    PKI_init();
    if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA)
	Rf_error("key must be RSA private key");
    rsa = EVP_PKEY_get1_RSA(key);
    if (!rsa)
	Rf_error("%s", ERR_error_string(ERR_get_error(), NULL));
    if (RSA_sign(type,
		 (const unsigned char*) RAW(what), LENGTH(what),
		 (unsigned char *) buf, &siglen, rsa) != 1)
	Rf_error("%s", ERR_error_string(ERR_get_error(), NULL));
    res = allocVector(RAWSXP, siglen);
    memcpy(RAW(res), buf, siglen);
    return res;
}
开发者ID:rOpenSec,项目名称:PKI,代码行数:43,代码来源:pki-x509.c

示例8: ASN1err

EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
	     long length)
	{
	EVP_PKEY *ret;
	
	if ((a == NULL) || (*a == NULL))
		{
		if ((ret=EVP_PKEY_new()) == NULL)
			{
			ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
			return(NULL);
			}
		}
	else	ret= *a;

	ret->save_type=type;
	ret->type=EVP_PKEY_type(type);
	switch (ret->type)
		{
#ifndef OPENSSL_NO_RSA
	case EVP_PKEY_RSA:
		if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,
			(const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
			{
			ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
			goto err;
			}
		break;
#endif

	default:
		ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
		goto err;
		/* break; */
		}
	if (a != NULL) (*a)=ret;
	return(ret);
err:
	if ((ret != NULL) && ((a == NULL) || (*a != ret)))
			EVP_PKEY_free(ret);
	return(NULL);
	}
开发者ID:Aorjoa,项目名称:bootloader,代码行数:42,代码来源:d2i_pu.c

示例9: meth_pubkey

/**
 * Extract public key in PEM format.
 */
static int meth_pubkey(lua_State* L)
{
  char* data;
  long bytes;
  int ret = 1;
  X509* cert = lsec_checkx509(L, 1);
  BIO *bio = BIO_new(BIO_s_mem());
  EVP_PKEY *pkey = X509_get_pubkey(cert);
  if(PEM_write_bio_PUBKEY(bio, pkey)) {
    bytes = BIO_get_mem_data(bio, &data);
    if (bytes > 0) {
      lua_pushlstring(L, data, bytes);
      switch(EVP_PKEY_type(pkey->type)) {
        case EVP_PKEY_RSA:
          lua_pushstring(L, "RSA");
          break;
        case EVP_PKEY_DSA:
          lua_pushstring(L, "DSA");
          break;
        case EVP_PKEY_DH:
          lua_pushstring(L, "DH");
          break;
        case EVP_PKEY_EC:
          lua_pushstring(L, "EC");
          break;
        default:
          lua_pushstring(L, "Unknown");
          break;
      }
      lua_pushinteger(L, EVP_PKEY_bits(pkey));
      ret = 3;
    }
    else
      lua_pushnil(L);
  }
  else
    lua_pushnil(L);
  /* Cleanup */
  BIO_free(bio);
  EVP_PKEY_free(pkey);
  return ret;
}
开发者ID:Chingliu,项目名称:luasec,代码行数:45,代码来源:x509.c

示例10: syslog_sign_init

int
syslog_sign_init()
{
    SSL *ssl;

    sign_global_conf =  EVP_MD_CTX_create();
    EVP_MD_CTX_init(sign_global_conf);

    if (ssl = SSL_new(ssl_global_conf)) {
        dprintf("Try to get keys from TLS X.509 cert...\n");

        if (!(xcert = SSL_get_certificate(ssl))) {
            logerror("SSL_get_certificate() failed");
            SSL_free(ssl);
            return EXIT_FAILURE;
        }
        if (!(eprivkey = SSL_get_privatekey(ssl))) {
            logerror("SSL_get_privatekey() failed");
            SSL_free(ssl);
            return EXIT_FAILURE;
        }
        if (!(epubkey = X509_get_pubkey(xcert))) {
            logerror("X509_get_pubkey() failed");
            SSL_free(ssl);
            return EXIT_FAILURE;
        }
    }

    SSL_free(ssl);

    if (EVP_PKEY_DSA != EVP_PKEY_type(epubkey->type)) {
        dprintf("X.509 cert has no DSA key\n");
        EVP_PKEY_free(epubkey);
        eprivkey = NULL;
        epubkey = NULL;
    } else {
        dprintf("Got public and private key "
                "from X.509 --> use type PKIX\n");

        sign_method = EVP_dss1();
    }
}
开发者ID:haad,项目名称:syslogd,代码行数:42,代码来源:sign.c

示例11: PKI_X509_KEYPAIR_VALUE_get_algor

PKI_ALGOR * PKI_X509_KEYPAIR_VALUE_get_algor ( PKI_X509_KEYPAIR_VALUE *pVal )
{
	PKI_ALGOR *ret = NULL;

	int size = -1;
	int algId = -1;

	size = PKI_X509_KEYPAIR_VALUE_get_size(pVal);
	if (size <= 0) PKI_ERROR(PKI_ERR_GENERAL, "Key size is 0!");

	switch (EVP_PKEY_type(pVal->type))
	{
		case EVP_PKEY_DSA:
			algId = PKI_ALGOR_DSA_SHA1;
			break;

		case EVP_PKEY_RSA:
			algId = PKI_ALGOR_RSA_SHA256;
			break;

#ifdef ENABLE_ECDSA
		case EVP_PKEY_EC:
			if ( size < 256 ) {
				algId = PKI_ALGOR_ECDSA_SHA1;
			} else if ( size < 384 ) {
				algId = PKI_ALGOR_ECDSA_SHA256;
			} else if ( size < 512 ) {
				algId = PKI_ALGOR_ECDSA_SHA384;
			} else {
				algId = PKI_ALGOR_ECDSA_SHA512;
			};
			break;
#endif

		default:
			return ret;
	};

	if( algId > 0 ) ret = PKI_ALGOR_get ( algId );

	return ret;
};
开发者ID:Brenhilt,项目名称:libpki,代码行数:42,代码来源:pki_keypair.c

示例12: getPrivKeyType

int getPrivKeyType(EVP_PKEY *pkey)
{
  int rValue = CERT_OBJECT_MAX_OBJECT;

  switch (EVP_PKEY_type(pkey->type))
    {
    case EVP_PKEY_RSA:
      rValue = CERT_OBJECT_RSA_PRIVATE_KEY;
      break;

    case EVP_PKEY_DSA:
      rValue = CERT_OBJECT_DSA_PRIVATE_KEY;
      break;
    case EVP_PKEY_EC:
      rValue = CERT_OBJECT_EC_PRIVATE_KEY;
      break;
    }

  return rValue;
}
开发者ID:openwebos,项目名称:pmcertificatemgr,代码行数:20,代码来源:cert_utils.c

示例13: TEST_P

TEST_P(KeymasterGenerateECTest, GenerateKeyPair_EC_Success) {
    keymaster_keypair_t key_type = TYPE_EC;
    keymaster_ec_keygen_params_t params = {
            .field_size = GetParam(),
    };

    uint8_t* key_blob;
    size_t key_blob_length;

    ASSERT_EQ(0,
            sDevice->generate_keypair(sDevice, key_type, &params, &key_blob, &key_blob_length))
            << "Should generate an EC key with " << GetParam() << " field size";
    UniqueKey key(&sDevice, key_blob, key_blob_length);

    uint8_t* x509_data = NULL;
    size_t x509_data_length;
    ASSERT_EQ(0,
            sDevice->get_keypair_public(sDevice, key_blob, key_blob_length,
                    &x509_data, &x509_data_length))
            << "Should be able to retrieve EC public key successfully";
    UniqueBlob x509_blob(x509_data, x509_data_length);
    ASSERT_FALSE(x509_blob.get() == NULL)
            << "X509 data should be allocated";

    const unsigned char *tmp = static_cast<const unsigned char*>(x509_blob.get());
    Unique_EVP_PKEY actual(d2i_PUBKEY((EVP_PKEY**) NULL, &tmp,
            static_cast<long>(x509_blob.length())));

    ASSERT_EQ(EVP_PKEY_EC, EVP_PKEY_type(actual.get()->type))
            << "Generated key type should be of type EC";

    Unique_EC_KEY ecKey(EVP_PKEY_get1_EC_KEY(actual.get()));
    ASSERT_FALSE(ecKey.get() == NULL)
            << "Should be able to extract EC key from EVP_PKEY";

    ASSERT_FALSE(EC_KEY_get0_group(ecKey.get()) == NULL)
            << "EC key should have a EC_GROUP";

    ASSERT_TRUE(EC_KEY_check_key(ecKey.get()))
            << "EC key should check correctly";
}
开发者ID:MIPS,项目名称:hardware-libhardware,代码行数:41,代码来源:keymaster_test.cpp

示例14: PKI_verify_RSA

SEXP PKI_verify_RSA(SEXP what, SEXP sMD, SEXP sKey, SEXP sig) {
    int md = asInteger(sMD), type;
    EVP_PKEY *key;
    RSA *rsa;
    switch (md) {
    case PKI_MD5:
  type = NID_md5;
  break;
    case PKI_SHA1:
  type = NID_sha1;
  break;
    case PKI_SHA256:
  type = NID_sha256;
  break;
    default:
  Rf_error("unsupported hash type");
  }
    if (TYPEOF(what) != RAWSXP ||
  (md == PKI_MD5 && LENGTH(what) != MD5_DIGEST_LENGTH) ||
  (md == PKI_SHA1 && LENGTH(what) != SHA_DIGEST_LENGTH) ||
  (md == PKI_SHA256 && LENGTH(what) != SHA256_DIGEST_LENGTH))
	Rf_error("invalid hash");
    if (!inherits(sKey, "public.key") && !inherits(sKey, "private.key"))
	Rf_error("key must be RSA public or private key");
    key = (EVP_PKEY*) R_ExternalPtrAddr(sKey);
    if (!key)
	Rf_error("NULL key");
    if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA)
	Rf_error("key must be RSA public or private key");
    rsa = EVP_PKEY_get1_RSA(key);
    if (!rsa)
	Rf_error("%s", ERR_error_string(ERR_get_error(), NULL));
    return
	ScalarLogical( /* FIXME: sig is not const in RSA_verify - that is odd so in theory in may modify sig ... */
		      (RSA_verify(type,
				  (const unsigned char*) RAW(what), LENGTH(what),
				  (unsigned char *) RAW(sig), LENGTH(sig), rsa) == 1)
		      ? TRUE : FALSE);
}
开发者ID:rOpenSec,项目名称:PKI,代码行数:39,代码来源:pki-x509.c

示例15: switch

QSslKey SafetPKCS12::keyFromEVP( EVP_PKEY * evp )
{
    EVP_PKEY *key = (EVP_PKEY*)evp;
    unsigned char *data = NULL;
    int len = 0;
    QSsl::KeyAlgorithm alg;
    QSsl::KeyType type;

    switch( EVP_PKEY_type( key->type ) )
    {
        case EVP_PKEY_RSA:
        {
            RSA *rsa = EVP_PKEY_get1_RSA( key );
            alg = QSsl::Rsa;
            type = rsa->d ? QSsl::PrivateKey : QSsl::PublicKey;
            len = rsa->d ? i2d_RSAPrivateKey( rsa, &data ) : i2d_RSAPublicKey( rsa, &data );
            RSA_free( rsa );
            break;
        }
        case EVP_PKEY_DSA:
        {
            DSA *dsa = EVP_PKEY_get1_DSA( key );
            alg = QSsl::Dsa;
            type = dsa->priv_key ? QSsl::PrivateKey : QSsl::PublicKey;
            len = dsa->priv_key ? i2d_DSAPrivateKey( dsa, &data ) : i2d_DSAPublicKey( dsa, &data );
            DSA_free( dsa );
            break;
        }
        default: break;
    }

    QSslKey k;
    if( len > 0 )
        k = QSslKey( QByteArray( (char*)data, len ), alg, QSsl::Der, type );
    OPENSSL_free( data );

    return k;
}
开发者ID:Cenditel,项目名称:pysafet,代码行数:38,代码来源:safetpkcs12.cpp


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