Reputation: 31
I am using bouncy castle RsaPrivateCrtKeyParameter
to read RSA private key.
I want to get some property to identify the RSA private key uniquely.
privateKey = bytes of the RSA privatekey
using (Stream stream = new MemoryStream(privateKey))
{
using (var reader = new StreamReader(stream))
{
RsaPrivateCrtKeyParameters rsaPrivatekey;
var privateKeyObject = new PemReader(reader).ReadObject();
rsaPrivatekey = (RsaPrivateCrtKeyParameters) privateKeyObject;
//KeyId = here some property of rsaPrivatekey to indentify this key uniquely
}
}
I am casting the rsaPrivatekey
to Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters
.
Can I use any of this class property to identify the key uniquely?
Can I use any of this methods - DP, DQ, P, PublicExponent, Q, QInv or GetHashCode to get the unique data to indentify the key.
My requirment is to get human readable string from the rsa key (like KeyId) so has to identify each rsa key uniquely. It might be some KeyId or thumbprint/fingureprint
Upvotes: 0
Views: 347
Reputation: 41974
If the public exponent is fixed (usually 65537) you should just use some of the low-order bits of the public key modulus to form an index, but don't bother with the very lowest-order bit because it's always "1". This is of course very fast.
By using only the public key you don't risk leaking information about the private key into the index. If you are storing both private and public keys in the same database then you can do something like append a "1" bit then take the original index and append either a "1" bit or a "0" bit depending on whether the public or private key is being indexed.
Upvotes: 1
Reputation: 1825
He is wanting to store the Private keys, but give them an index parameter that is unique based on the content of the key.
In which case- I would recommend using Sha256 hashing of the private or public key associated with the private key, and then store both in a database.
Upvotes: 1