简体   繁体   English

使用 openssl 从 PEM 格式的 x 和 y 组件获取 ecc 公钥

[英]get ecc public key from x and y components in PEM format using openssl

Can I get the ecc public key from x and y components in PEM format using openssl?我可以使用 openssl 从 PEM 格式的 x 和 y 组件获取 ecc 公钥吗?

X:
1d 43 15 e3 84 99 d6 f6  9f 49 61 8a ae ec f2 4f

Y:
b5 1a 86 cf f9 0e 01 af  3a 9a 52 b3 c6 58 2c 48  

thank you!!!!!!!!!!!谢谢你!!!!!!!!!!!

Yes it is possible.对的,这是可能的。 Here an example in C.这是 C 中的示例。

int main(void)
{
  EC_GROUP *group;
  EC_POINT *point;
  EC_KEY *key;
  BIGNUM *x, *y;
  BIO *out;

  ERR_load_crypto_strings();
  OpenSSL_add_all_algorithms();

  group = EC_GROUP_new_by_curve_name(NID_secp256k1);

  x = BN_new();
  y = BN_new();

  BN_hex2bn(&x, "1d4315e38499d6f69f49618aaeecf24f");
  BN_hex2bn(&y, "b51a86cff90e01af3a9a52b3c6582c48");

  /* create EC point from X and Y */
  point = EC_POINT_new(group);
  EC_POINT_set_affine_coordinates_GFp(group, point, x, y, NULL);

  /* Create a new EC key and set the public key */
  key = EC_KEY_new();
  EC_KEY_set_group(key, group);
  EC_KEY_set_public_key(key, point);

  out = BIO_new(BIO_s_file());
  BIO_set_fp(out, stdout, BIO_NOCLOSE);
  PEM_write_bio_EC_PUBKEY(out, key);

  /* Clean up */
  BN_free(x);
  BN_free(y);
  EC_POINT_free(point);
  EC_GROUP_free(group);
  EC_KEY_free(key);
  BIO_free(out);

  return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM