How to delete multiple certs from keystore - keytool

I have one keystore which has around 30 certificates i want to delete most of them.
How can i do it rather than doing keytool -delete -alias <AliasName> -keystore keystore.jks

Related

Pasting a command line into VSCode's integrated terminal executes part of it prematurely

when I copy my code into terminal in VScode . terminal executes my code before my code finish copying.
keytool -list -v \
-alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
how to turn off this feature
sorry my english is bad, i use google translate.
Your integrated terminal in Visual Studio Code is running PowerShell, which doesn't support use of \ as a line-continuation character.
Either use ` (a backtick), making sure that it is the very last character on the line, or paste the command as a single line.
Additionally, PowerShell doesn't understand %USERPROFILE% as an environment-variable reference (only cmd.exe does); use $env:USERPROFILE instead.
Therefore:
With line continuation:
keytool -list -v `
-alias androiddebugkey -keystore $env:USERPROFILE\.android\debug.keystore
Single-line:
keytool -list -v -alias androiddebugkey -keystore $env:USERPROFILE\.android\debug.keystore

Sign a file exe windows ¬ Convert .pem to pfx

I am trying to sign a .exe file and I have a certificate and private key in format .pem.
I convert my cert using openssl to format .pfx
openssl pkcs12 -export -in "cert.pem" -inkey "key.pem" -out certificate.pfx -certfile "CA.cer"
I try using signtool
signtool sign /f "certificate.pfx" /p mypass /t http://timestamp.comodoca.com/authenticode "app.exe"
But I have the next error
SignTool Error: No certificates were found that met all the given criteria.
Reference
Signing .exe with .cer file (what is my certificate's name that signtool.exe is asking for?)

Why do mage.exe need administrative privileges to access certificate, but signtool.exe do not

I'm making a CI build task in PowerShell to sign an assembly and the manifest with signtool and mage.
It works great, except that I have to run PowerShell as Administrator to get mage to accept the certificate. What I find really strange is that signtool can use the same certificate without privileges.
The certificate is a .pfx file.
Script:
signtool sign /f $certPath /p $certPassword /q /t $timestampUri "Example.dll"
mage -s "Example.dll.manifest" -CertFile $certPath -Password $certPassword -ti $timestampUri
Without privileges:
Done Adding Additional Store
Successfully signed and timestamped: Example.dll
Unable to open certificate "D:\example.pfx":
Access denied.
With privileges:
Done Adding Additional Store
Successfully signed and timestamped: Example.dll
Example.dll.manifest successfully signed
Does anyone know what is going on here?
Edit:
I used Procmon as adviced. Log below in CSV
Procmon logs

Powershell openssl ObjectNotFound in windows server 2012

while trying to convert the private key file in PKCS12 format to PEM format (which is used by Wireshark) in two stages by using the openssl tool got the below error
PS C:\OpenSSL-Win64\bin> openssl pkcs12 -nodes -in test_cer123456.pfx -out key.pem -nocerts -nodes
openssl : The term 'openssl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ openssl pkcs12 -nodes -in test_cer123456.pfx -out key.pem -nocerts -nodes
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (openssl:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command openssl was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by
default. If you trust this command, instead type ".\openssl". See "get-help about_Command_Precedence" for more details.
PS C:\OpenSSL-Win64\bin>
Could some one help me on this.?
Note : I was following this post
Powershell doesn't include current directory as a part of search path. The error message actually tells you this and explains what to do (emphasis added):
Suggestion [3,General]: The command openssl was not found, but does
exist in the current location. Windows PowerShell does not load
commands from the current location by default. If you trust this
command, instead type ".\openssl". See "get-help
about_Command_Precedence" for more details.

unable to generate a keystore from an existing certificate file

I've lost my keystore file that was used to make release build for an android app. But I've the certificate file. Now I want to generate a new keystore from this existing certificate file but I'm unable to do that because I've forgot the alias name that was set when the keystore was created for the first time. Is there a way that I can use the same certificate file and generate a new keystore ? I have tried the following command but it didn't work.
keytool -import -alias foo -file certfile.cer -keystore publicKey.store
Does this link help ?
Generate a keystore using following command:
keytool -genkey -alias tomcat -keyalg RSA -keystore keystore.jks
Import CER file in java keystore:
keytool -importcert -file certificate.cer -keystore keystore.jks -alias "Alias"