Generate prime number using OpenSSL

10,585

OpenSSL version 1.0.0 and newer adds -generate option to the prime command:

$ openssl prime -generate -bits 2048 -hex
D668FDB1968891AE5D858E641B79C4BA18ABEF8C571CBE004EA5673FB3089961E4670681B794063592124D13FF553BBD5CCC81106A9E5F7D87370DD5DA6342B1DAC13CD2E584759CDEC3E76AEFB799848E48EA9C218F53FE3103E1081B8154AD41DDCB931175853FE3D433CECD886B4D94C211EAE01AE5EA93F8FBD6812A9DEF0308378EE963B3C39F80865BA0E1D957683F4ED77ADA9812091AA42E9A56F43C37185223FF9E3DD03C312E71DED072E5686873B3CA6F5F575C569FB0A10CFEA17D7FEB898A8A02549FF6E4B7A1FBCE78656D3DCF227318EEEF8E601C23AA32DF41A61F04D39FC752F70A809D636238340B7B929F0CDBA629F7DE6AAAC44D2BA5
Share:
10,585
user2835948
Author by

user2835948

Updated on June 04, 2022

Comments

  • user2835948
    user2835948 almost 2 years

    How can I generate a large random prime using openssl, I found out how to generate a random number and check if it is prime but I have not been able to automate the process of checking the primality, here is the command that i am using: openssl rand -hex 256 | xargs openssl prime -hex

    Should I use a while loop to repeatedly check if the result is prime? How can I automate the process of checking if the result does not contain the keyword "not",

    This is all the further i got on writing the while loop:

    while [{openssl rand -hex 256 | xargs openssl prime -hex} = *"$not"*]