Posts

Showing posts with the label Openssl

Convert From P7B To PEM Via OpenSSL

Answer : Solution 1: Try this: $ openssl pkcs7 -inform der -in a.p7b -out a.cer If it doesn't work, brings to a Windows machine and export follow this guide. Solution 2: So to combine the above answers, the command is: openssl pkcs7 -in cert.p7b -inform DER -print_certs -out cert.pem Verified to be working on Windows, using OpenSSL-Win64 /Thanks Bogdan for spotting the error Solution 3: I followed this guide that instructs you to change the header/footer lines from -----BEGIN PKCS #7 SIGNED DATA----- [data] -----END PKCS #7 SIGNED DATA----- to -----BEGIN CERTIFICATE----- [data] -----END CERTIFICATE----- Then run the command openssl pkcs7 -in foo.modified.crt -print_certs -out foo.certs (where foo.modified.crt is the file that you saved the modified version into). This gave me the same results as running through a Windows certificate export as suggested in other answers. Solution 4: As far as I know, the following should convert a pkcs7 cert to a pem openssl pkcs7 -in certific...

Convert NSData To String?

Answer : Objective-C You can use (see NSString Class Reference) - (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding Example: NSString *myString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding]; Remark : Please notice the NSData value must be valid for the encoding specified (UTF-8 in the example above), otherwise nil will be returned: Returns nil if the initialization fails for some reason (for example if data does not represent valid data for encoding). Prior Swift 3.0 String(data: yourData, encoding: NSUTF8StringEncoding) Swift 3.0 Onwards String(data: yourData, encoding: .utf8) See String#init(data:encoding:) Reference Prior Swift 3.0 : String(data: yourData, encoding: NSUTF8StringEncoding) For Swift 4.0: String(data: yourData, encoding: .utf8) I believe your "P" as the dataWithBytes param NSData *keydata = [NSData dataWithBytes:P length:len]; should be "buf" NSData *keydata = [NSData dataWithBytes:buf length:len]; sin...

Converting Pfx To Pem Using Openssl

Answer : Another perspective for doing it on Linux... here is how to do it so that the resulting single file contains the decrypted private key so that something like HAProxy can use it without prompting you for passphrase. openssl pkcs12 -in file.pfx -out file.pem -nodes Then you can configure HAProxy to use the file.pem file. This is an EDIT from previous version where I had these multiple steps until I realized the -nodes option just simply bypasses the private key encryption. But I'm leaving it here as it may just help with teaching. openssl pkcs12 -in file.pfx -out file.nokey.pem -nokeys openssl pkcs12 -in file.pfx -out file.withkey.pem openssl rsa -in file.withkey.pem -out file.key cat file.nokey.pem file.key > file.combo.pem The 1st step prompts you for the password to open the PFX. The 2nd step prompts you for that plus also to make up a passphrase for the key. The 3rd step prompts you to enter the passphrase you just made up to store decrypted. The 4th puts it all t...