demo_sm9_keygen.c 885 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <gmssl/sm9.h>
  13. int main(void)
  14. {
  15. SM9_SIGN_MASTER_KEY sign_master;
  16. SM9_SIGN_KEY sign_key;
  17. sm9_sign_master_key_generate(&sign_master);
  18. printf("SM9 Master Secret\n");
  19. sm9_sign_master_key_info_encrypt_to_pem(&sign_master, "P@ssw0rd", stdout);
  20. printf("SM9 Public Parameters\n");
  21. sm9_sign_master_public_key_to_pem(&sign_master, stdout);
  22. sm9_sign_master_key_extract_key(&sign_master, "alice", strlen("alice"), &sign_key);
  23. printf("SM9 private key for ID '%s'\n", "alice");
  24. sm9_sign_key_info_encrypt_to_pem(&sign_key, "123456", stdout);
  25. return 0;
  26. }