This is fine if you want to generate a key pair once, but what if you want. The resulting PEM strings be saved and then later fed to OpenSSL::PKey::RSA.
- I generate an ssh key: ssh-keygen -t rsa -b 4096Generating public/private rsa key pair.Enter file in which to save the key (/Users/kurtostfeld/.ssh/idrsa): rsakeyEnter passphrase (empty for.
- Generate RSA public/private key pair Generate private key: openssl genrsa -out privatekey.pem 1024 Convert private key to PKCS8 format: ope.
- You can generate a 2048-bit RSA key pair with the following commands. Openssl genpkey -algorithm RSA -out rsaprivate.pem -pkeyopt rsakeygenbits:2048.
- I'd like to generate RSA 1024 key pairs. What I got from google is openssl genrsa -out privatekey.txt 1024 openssl rsa -in privatekey.txt -pubout -out publickey.txtbut why these two files are.
Holographic print detection is an essential task in applications requiring automatic validation of government-issued ids, banknotes, credit cards and other printed documents from a video stream. Today we’ll discuss how to approach this problem with Python and OpenCV.
Unique features of holographic print
Human can instantly recognize a holographic print by two main characteristics:
- highly reflective
- color changes within a wide range depending on relative position of the light source
Some prints, like logos on credit cards, may have more advanced security features when holographic print incorporates specific sequence of images which is ‘played’ when you rotate it against the light source. In this article, we will focus on just two main characteristics above.
Sample data
First, we’ll need to collect the data for analysis – a sequence of frames capturing the holographic print from different angles under directional light source. The optimal way to achieve this is to record a video with a smartphone with torch turned on, like this:
Now, as we have the data to experiment, what’s our plan?
- Perform segmentation – accurately detect the zone of interest on each frame
- Unwarp and stack zone of interest pixels in a way ensuring coordinates match between frames
- Analyze resulting data structure to find coordinates of hologram’s pixels
- Display results
Image segmentation
Because the object which have holographic print on it (or a camera) will be moving, we’ll need to detect the initial position and track it throughout the frame sequence. In this case, a banknote has a rectangular shape. Let’s start by identifying the biggest rectangle on the image.
Here, goodFeaturesToTrack function is used to get strong corners from the image, then maximum rectangle of a proper orientation is estimated.
Tracking the movement
An obvious way to track the movement would be to detect corners in a similar way on all consecutive frames, however, this method is not robust to changes in the background and severe rotations of the object. Instead, we will detect initial features inside the rectangle, and estimate their new positions on consecutive frames using optical flow algorithm
Note: we could skip rectangle detection altogether and detect keypoints on full image, but it’s unrealistic to have such a convenient neutral background in a real-world scenario.
Now it’s possible to look for same keypoints on every next frame using a function which implements Lucas-Kanade method. Additional trick here is to filter out unstable keypoints by running an algorithm forward and backwards, and then cross-checking result with known initial keypoints.
To map pixel coordinates of a given frame to source frame’s coordinates, we’ll need to estimate a transformation matrix with findHomography
function, which takes two lists of source and destination keypoints and returns a transformation matrix.
Here’s how the video looks after unwarping. Not perfectly aligned, because banknote have some curvature of itself, but much better!
Detecting a hologram
Previous processing steps allowed us to get a data structure like this:
Where z-axis represents the number of frame in the sequence. Let’s create histograms of individual pixel values in HSV color space.
HSV space
As you can see, Hue value have much wider range for pixels of the hologram. Let’s filter pixels based on that and highlight the ones with 5% – 95% percentile range above a certain threshold. Let’s also cutoff dark pixels with too low S and V values.
Success! The holograms most visible on the video are highlighted, but we have some false positives. What’s wrong with these pixels?
That is the result of inaccurate unwarping, pixels laying on strong edges have two distinct values. The difference with hologram pixels is that they are not taking all the values in between of these histogram peaks. In other words, their distribution is less uniform. We can use Chi-squared test to check for uniformity and filter these pixels out:
Much better now! Here’s how it looks overlayed on original video:
Two top pieces are highlighted, and the bottom ones, which look more like a foil on this video, aren’t. Another sample with a credit card having a better hologram:
That’s it. See full code on my github. Thanks for reading!
OpenSSL is a giant command-line binary capable of a lot of various securityrelated utilities. Each utility is easily broken down via the first argument ofopenssl
. For instance, to generate an RSA key, the command to use will beopenssl genpkey
.
Generate 2048-bit AES-256 Encrypted RSA Private Key .pem
The following command will result in an output file of private.pem in whichwill be a private RSA key in the PEM format.
Openssl Command To Generate Rsa Key Pair
Let’s break this command down:
Rsa_generate_key_ex Example
openssl
: The binary that contains the code to generate an RSA key (and manyother utilities).genpkey
: Specifies the utility to use.-algorithm RSA
: Specifies to use the RSA algorithm.-aes256
: Specifies to use the AES-256 cipher, which is newer and moresecure than DES. Default is no cipher.-out private.pem
: Specifies that a file named “private.pem” should becreated with the contents of the private key. Default isSTDOUT
.
When executing this command, it will ask for a password to encrypt the keywith. After selecting a password, a file will be created in the currentdirector named private.pem
.
Private RSA keys generated with this utility start with the text -----BEGIN PRIVATE KEY-----
.
You can inspect this file with the command cat private.pem
.
Export Public RSA Key From Private Key
In order to export the public key from the freshly generated private RSA Key,the openssl rsa
utility, which is used for processing RSA keys.
The command to export a public key is as follows:
This will result in a public key, due to the flag -pubout.
Inspect this file with cat public.pem
:
The public key can be uploaded to other servers and services to encrypt datafor the private key to decrypt.
This file will start with -----BEGIN PUBLIC KEY-----
. If this file doesn’tstart with “BEGIN PUBLIC KEY”, do not upload it as a public key to any source!