GPG: cannot import private/secret key - encryption

I have a public/private GPG keypair. When I try to gpg --import either the public or the private key, only the public keyring is updated:
[root#ip-10-24-5-35 ~]# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub 4096R/A6E928B1 2018-07-02
uid saids_ftp (some description) <said#example.com>
sub 4096R/5010A53E 2018-07-02
[root#ip-10-24-5-35 ~]# gpg --list-secret-keys
[root#ip-10-24-5-35 ~]#
Later, when I try to decrypt a file, I get the following output:
[root#ip-10-24-5-35 raw]# gpg --decrypt file.txt.gpg
gpg: encrypted with RSA key, ID FFAB8C83
gpg: encrypted with RSA key, ID D66EFA2A
gpg: encrypted with RSA key, ID 2FA063D3
gpg: encrypted with RSA key, ID 038D4A79
gpg: encrypted with ELG key, ID D5D81FBC
gpg: encrypted with RSA key, ID 45ED8372
gpg: encrypted with RSA key, ID CC1446EE
gpg: encrypted with 4096-bit RSA key, ID 5010A53E, created 2018-07-02
"saids_ftp (some description) <said#example.com>"
gpg: encrypted with RSA key, ID 75BB9DFE
gpg: encrypted with RSA key, ID B2ECF5E4
gpg: encrypted with ELG key, ID 2AD775F8
gpg: encrypted with RSA key, ID B5F82E2E
gpg: encrypted with RSA key, ID D8098B00
`enter code here`gpg: decryption failed: No secret key
Is there something wrong with my private key? I'm not sure how I exported it in the past, as the server that the key was created on is no longer available.

Related

ESP32 firebase OAuth2.0 access token error -116

i'm trying to connect esp32 to firestore but an error appear on the serial monitor
Token info: type = OAuth2.0 access token, status = error
Token error: code: -116, message: mbedTLS, mbedtls_pk_parse_key: PK - Invalid key tag or value
i'm using source code from https://github.com/mobizt/Firebase-ESP-Client/blob/main/examples/Firestore/ImportDocuments/ImportDocuments.ino
Most likely you've not provided the private key string correctly (TLS libraries are rather picky about that), or the private key is not in correct format.
E.g. this is how you generate a 2048 bit RSA keypair in PKCS8 format (which is what the sample code appears to use):
$ ssh-keygen -t rsa -b 2048 -m PKCS8 -f testkey
This is how you add the resulting private key as a multiline raw string literal in C++:
const char PRIVATE_KEY[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7lmkdHSxCOVt+Wt4vsoegZAydm8mtAfA0W63tgMDgKpCyqtn/H
vl6v08jHQwKBgQDwtO48doKvlIRtcAZGghrS0FBOVuPP+2VIzIWdrO72oPeCtsAz
dPxf+HcIxLsH7NrD7rzetMuAqyJoe16OCz0Ep6K1aEidB5OPv1WPw/wFNLF9uWb9
VpQhM23oCYC4kOhPiOq234UTJSSy6Z//6mHBZUyKISmmsgAfykzjCKL7YQKBgDNQ
qCXIhGVtpLDN4ybLyz7mqdYbjFiv4QdDYau1He8ZVbjfRCvnGmlDWmNXJgGRUjI2
F7A+WJw3+IfWHwwsozgO4QopCXuQu6N+90cK85Bu+mMXUWtzd1wqHRABv8MZTw5Y
+9mjB8oMgAUP84jcpFxRSiSunUCkuZc0JkqaQ/KrAoGAYxtl+555GpXK9eLfrVOG
02czqaXssGXIi31aGTICy7Esk8OgaG+pd4brcICeYE/CQ6gDjt6m/dHcw+DFmeFX
nVDHCIIDB9SeHM0Z3wZi/JruCtoB6vTxhA5lA9QeI4TpZvYXQkuerRUzRvhxyzkV
PrYun0MrVLxiiwezSTxlyGw=
-----END PRIVATE KEY-----
)";

DES signature confusion

I was recently examining a file containing cleartext, then under the cleartext:
This is cleartext. A message presumably signed with the below certificate.
-----BEGIN CERTIFICATE-----
Proc-Type: 4,ENCRYPTED
Modulus: 31353732
DEK-Info: DES-CBC,656e733333
MIIBwcHBwcHBwcHAAgAAAcIAAAIAAAAAAAyZjAwMDAwMDAwZjAwMDBmMDAwMDAwM
DBmMDAwMDBmMGgwMDAwMDAwMGYwMGYwMGYwMDAwMGZmMDAwMDAwMDBmegAICGUHm
QBxb3mYbXBveW2ZcZYHaW9hAKoulAeZU29sU2+jAKougQCUcZZnmXGYB4JxlnmVU
G0HZ6pngi6XB3OCcZVxZ6oulXGUZ4J5lXGUB3lvaYFxlgeVZZd5l1BtM5Z5lWeUe
ZdQbXGZLoEAlHGWZ5lxmAeCZ4IubW9ncAB4cZZnmXGYB4JxmGeYKaopqnGYZ4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QbXGZLoEAl
HGWZ5lxmAeCcTeUcZZnmXGYB4JxmC6XB5ZrqnGYeZUHlimqcZgul2VnamcAqnGCc
ZYHZ6pllHmXUG1xmS6BAJRxlmeZcZgHgnFicZZnmXGYB4JxmHmVB5YHZ6pxlnmVB
5YHZ6plmGcAqmwHlwcAqmeXZ5QulwcAqnmXUG1xmS6BAJRxlmeZcZgHd4EAlHGWZ
5lxmAeCcZguly6UZZZlgS6YLpZtlXGYB2dwB4EAmAeCZ5lllAdnqmWYB5UHAKp5l
1BtcZkugQCUcWdQbXGZLoEAlHGWZ5lxmAeCcZYHmQcAqi4AqnGWLpcucWeZKapxg
meCeZVlgQCUB4JnmQCYeZdQbXGZLoEAlHE5AKp5l1BtcZkugQCUcZZnmXGYB4Jxl
geVcZYpqgeCZ2gHmQcAqi4AqnGYB5UugXGCcZYHlS6VeZdQbXGZLoEAZnmXUG1xm
S6BAJRxlmeZcZgHgnGYB2eqLoEAlnGWB5dmZ4Iul3GUZZZxlQeVcZRtlXGYB2eqc
Zh5l1BtcZkugTg=zJZkhn==
-----END CERTIFICATE-----
I googled DES-CBC and found that it was a symmetric key algorithm. From this information, through bruteforce, could the original secret key be found and the encrypted data be decrypted to cleartext? How about re-encrypted to yield the same encrypted text?

How do I decrypt the ciphertext given the private key with RSA?

I have this private key and I am trying to decrypt the ciphertext:
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAkfmJTVkwbRXOtWN76j2MAmbwCMReCkV3hWG+23zEmivwVEUtlUNvmFkSx9fFSRgGLMW+TPleLybU629fYDTXSPmIzLM3faxIyzyI2LJdRAaQMWo1FUcVI8ME5/BX9T5Ebu6D2dA8zJzJ68dGkHmhSxhOC97vLQfjj3tNCAL1IulyVk/ZyV6BVPxpiD3WB4rfo+SBe8H7019+dnaR/DcTcCsxF+oj7KOunfPPqBZBGMRe7ADj/vPYqgpoTWyA8m0juJyVNjqBnFUeyZEPwjqYUKEXpw64YXDZH/hbJI6VaFmj/KpMzBv/g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9Uoec/Dz4KhFN+L/AoGATnaM4pl/tv735KcNn+qpgyB2Qd01qasRahecchPZqujH0+roS3llDJFN09NG9BzmAQFi2yH7Asx5KmIHqyWiYqyMXGUcsauT3u+xsDYWxObqAW7q7sMCKlfRtsnEWli3FOWNufO0TBwGeL9xVjL3nXXIsD9J5/iq1cH/RuIVoX4=
-----END RSA PRIVATE KEY-----
The ciphertext:
M8zhAvxu/lkEcH42Eoe/cPjL6WJwPo1FZOK8Ta4SmigoHl9omd5Dol84vY3GfyzIZ0hHHp5gO3A4MjktImsLnT3Xx/myUearG/Ii24C+6irFapMqghziuMDYpeh7rs8G8ggE/rkjZaAAPSb/FgEDQkknL2qr4kxwyQybsnfmDDUqJ3q3lf0gRBDJ/2yr+aQyUcw3nK/zewbZjwlUeSyTvs76HhFtUDTyAlhB37961j9qfu+cxX34PtJlHWlF7k0WAuxQ4w7aCwkuQIvBOk/FUK3Ta1TrGEXg9iczPj6QacLI2DSjEPbODHsje82Fw+1ylcD1tF2mZ7GnnqtUw/9YoQ==
I tried to use these commands but without sucess:
openssl rsautl -decrypt -in ciphertext -out plaintext -inkey private_key
In this case I get the fallowing error:
rsa routines:RSA_EAY_PRIVATE_DECRYPT:data greater than mod len:rsa_eay.c:518
openssl enc -in ciphertext -out binarytext -d -a
openssl rsautl -decrypt -in binarytext -out plaintext -inkey private_key
If I try these 2 commands I get this error:
rsa routines: RA_padding_check_PKCS1_type_2:pkcs decoding error
rsa routines: RSA_EAY_PRIVATE_DECRYPT:padding check failed

Openssl cannot decrypt message using PuttyGen private key

I've created public and private keys using PuttyGen then the public key was used to encrypt a message.
I am now trying to decrypt such message using the private key with the following command:
echo [my encrypted message] | openssl enc -d -base64 -A | openssl rsautl -decrypt -inkey ~/.ssh/private.ppk
but I get the error:
unable to load Private Key
6870300:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:707:Expecting: ANY PRIVATE KEY
The private key looks like this (actual key omitted):
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20170724
Public-Lines: 6
[...]
Private-Lines: 14
[...]
Private-MAC: [...]
What's wrong?
Thanks to this guy I sorted it out.
I've reopened the private key with PuttyGen and exported as OpenSSH, then used this new file to decrypt the message.

How to convert DER formatted public key file to PEM form

I need to use the PEM formatted public key for some purpose, but not finding the command which can convert DER formatted public key to PEM formatted public key.
The command I have used -
openssl rsa -in user_id_rsa.pub -inform DER -outform PEM -out pubkey.pem
But i got the below error -
unable to load Private Key
139901900170912:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1337:
139901900170912:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:677:
139901900170912:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1337:
139901900170912:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:388:Type=RSA
My expected output should be in this format-
-----BEGIN RSA PUBLIC KEY-----
KEY CONTENT
-----END RSA PUBLIC KEY-----
Is anyone has try the same?

Resources