Why does RSA encrypted text give me different results for the same text

A secure RSA encryption is implemented with an appropriate padding scheme, which includes some randomness. See PKCS#1 or OAEP for more details. The RSA encryption encrypts message padded with ‘0’s and a string of random bit. In the process, the random string is “hidden” in the ciphertext by cryptographic hashing and XORing. On decryption, the … Read more

iOS SecKeyRef to NSData

use of undeclared identifier ‘publicTag’ The publicTag is just some unique identifier added to the Keychain items. In the CryptoExercise sample project it is defined as #define kPublicKeyTag “com.apple.sample.publickey” static const uint8_t publicKeyIdentifier[] = kPublicKeyTag; NSData *publicTag = [[NSData alloc] initWithBytes:publicKeyIdentifier length:sizeof(publicKeyIdentifier)]; Cast of an indirect pointer to an Objective-C pointer to ‘CFTypeRef ‘ (aka … Read more

Digital signature for a file using openssl

To Generate Private Key openssl genrsa -out privatekey.pem 2048 To Sign openssl dgst -sha256 -sign privatekey.pem -out data.txt.signature data.txt To Generate The Public Key dgst -verify requires the public key openssl rsa -in privatekey.pem -outform PEM -pubout -out publickey.pem To Verify openssl dgst -sha256 -verify publickey.pem -signature data.txt.signature data.txt In case of success: prints “Verified … Read more

CryptographicException “Key not valid for use in specified state.” while trying to export RSAParameters of a X509 private key

I believe that the issue may be that the key is not marked as exportable. There is another constructor for X509Certificate2 that takes an X509KeyStorageFlags enum. Try replacing the line: X509Certificate2 x = new X509Certificate2(@”C:\temp\certs\1\test.pfx”, “test”); With this: X509Certificate2 x = new X509Certificate2(@”C:\temp\certs\1\test.pfx”, “test”, X509KeyStorageFlags.Exportable);