How to encrypt a file with private key

NoTrust

I want to encrypt a file with a private key and decrypt it with a public key. A public key will be embedded in my app. So I want to have a guarantee that the file was created by me. How can I use gpg or openssl to implement it.

Gilles 'SO- stop being evil'

It makes no sense to encrypt a file with a private key.

Using a private key to attach a tag to a file that guarantees that the file was provided by the holder of the private key is called signing, and the tag is called a signature.

There is one popular cryptosystem (textbook RSA) where a simplified (insecure) algorithm uses has public and private keys of the same type, and decryption is identical to signature and encryption is identical to verification. This is not the case in general: even RSA uses different mechanisms for decryption and signature (resp. encryption and verification) with proper, secure padding modes; and many other algorithms have private and public keys that aren't even the same kind of mathematical objects.

So you want to sign the file. The de facto standard tool for this is GnuPG.

To sign a file with your secret key:

gpg -s /path/to/file

Use the --local-user option to select a secret key if you have several (e.g. your app key vs your personal key).

Transfer file.gpg to the place where you want to use the file. Transfer the public key as well (presumably inside the application bundle). To extract the original text and verify the signature, run

gpg file.gpg

If it's more convenient, you can transfer file itself, and produce a separate signature file which is called a detached signature. To produce the detached signature:

gpg -b /path/to/file

To verify:

gpg file.gpg file

You can additionally encrypt the file with the -e option. Of course this means that you need a separate key pair, where the recipient (specified with the -r option) has the private key and the producer has the public key.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to encrypt a file non-interactively (using a stored private key)

From Dev

How to encrypt data with RSA private key in python?

From Dev

How to encrypt data with RSA private key in python?

From Dev

How to encrypt and write RSA private key to file with PEM_Write_RSA_PrivateKey

From Dev

How to encrypt a file using my GPG private key so I can decrypt it later

From Dev

How to encrypt with private key and decrypt with public key in c# RSA

From Dev

.NET RSACryptoServiceProvider encrypt with 4096 private key, how to decrypt it on Android

From Dev

.NET RSACryptoServiceProvider encrypt with 4096 private key, how to decrypt it on Android

From Dev

Public/private key to encrypt AES session key

From Dev

c# RSA encrypt with private key

From Dev

Let's encrypt + certbot: where is the private key

From Dev

How to obtain private RSA key(private) as byte array in pgp file?

From Dev

How to obtain private RSA key(private) as byte array in pgp file?

From Dev

How to hardcode private key which can be used to encrypt once and decrypt many times?

From Dev

How to export a GPG private key and public key to a file

From Dev

How to Encrypt a Message With an Encryption Key

From Dev

how to load the private key from a .der file into java private key object

From Dev

How do I encrypt and store private messages?

From Dev

Encrypt files (private key, etc.) in an embedded system

From Dev

Encrypt files (private key, etc.) in an embedded system

From Java

How to convert a private key to an RSA private key?

From Dev

How to create .pfx file containing only one of private/public key

From Dev

JAVA: How to save a private key in a pem file with password protection

From Dev

How can I store a private api key in a source file?

From Dev

How to export Certificate and private key as a single file using java code?

From Dev

How to add PEM file as SSH private key to "known hosts"

From Dev

How to create private ssh RSA key from text file on mac?

From Dev

JAVA: How to save a private key in a pem file with password protection

From Dev

How to specify private key when decrypting a file using GnuPG?

Related Related

  1. 1

    How to encrypt a file non-interactively (using a stored private key)

  2. 2

    How to encrypt data with RSA private key in python?

  3. 3

    How to encrypt data with RSA private key in python?

  4. 4

    How to encrypt and write RSA private key to file with PEM_Write_RSA_PrivateKey

  5. 5

    How to encrypt a file using my GPG private key so I can decrypt it later

  6. 6

    How to encrypt with private key and decrypt with public key in c# RSA

  7. 7

    .NET RSACryptoServiceProvider encrypt with 4096 private key, how to decrypt it on Android

  8. 8

    .NET RSACryptoServiceProvider encrypt with 4096 private key, how to decrypt it on Android

  9. 9

    Public/private key to encrypt AES session key

  10. 10

    c# RSA encrypt with private key

  11. 11

    Let's encrypt + certbot: where is the private key

  12. 12

    How to obtain private RSA key(private) as byte array in pgp file?

  13. 13

    How to obtain private RSA key(private) as byte array in pgp file?

  14. 14

    How to hardcode private key which can be used to encrypt once and decrypt many times?

  15. 15

    How to export a GPG private key and public key to a file

  16. 16

    How to Encrypt a Message With an Encryption Key

  17. 17

    how to load the private key from a .der file into java private key object

  18. 18

    How do I encrypt and store private messages?

  19. 19

    Encrypt files (private key, etc.) in an embedded system

  20. 20

    Encrypt files (private key, etc.) in an embedded system

  21. 21

    How to convert a private key to an RSA private key?

  22. 22

    How to create .pfx file containing only one of private/public key

  23. 23

    JAVA: How to save a private key in a pem file with password protection

  24. 24

    How can I store a private api key in a source file?

  25. 25

    How to export Certificate and private key as a single file using java code?

  26. 26

    How to add PEM file as SSH private key to "known hosts"

  27. 27

    How to create private ssh RSA key from text file on mac?

  28. 28

    JAVA: How to save a private key in a pem file with password protection

  29. 29

    How to specify private key when decrypting a file using GnuPG?

HotTag

Archive