Questions tagged [encryption]

Encryption is the process of transforming information (called plaintext) into an unreadable form (called ciphertext) using an encryption algorithm using a secondary parameter (called an encryption key). Only those who possess the decryption key can easily reverse the process and recover the original plaintext. Conceptual questions about encryption may get better answers on crypto.stackexchange.com.

In cryptography, encryption is the process of transforming information (called plaintext) into an unreadable form (called ciphertext) using an encryption algorithm combined with a parameter called an encryption key. Reversing the process, that is transforming the ciphertext into plaintext, is called decryption. Only those who possess the decryption key can reverse the process and recover the original plaintext.

There are 2 types of encryption methods generally:

  • symmetric
  • asymmetric

In symmetric encryption the encryption and decryption keys are the one and the same; this single key is sometimes called the shared secret key. Rijndael(AES), TwoFish, and Cha-Cha are examples of symmetric encryption algorithms.

In asymmetric encryption, also known as public key encryption, the encryption and decryption keys are different. The encryption key is called the public key and the decryption key is called the private key. RSA, Diffie-Hellman (DH), El-Gamal (ElG), and elliptic curve variants of DH and ElG are examples of public key encryption algorithms.

The term "encryption" should be reserved for transformations intended to be reversed or "decrypted". In particular, cryptographic transformations intended to be one way, such as cryptographic hash algorithms (e.g. SHA1, SHA2, SHA3) and password hashing algorithms (e.g. bcrypt, scrypt) should not be referred to as "encryption".

Encryption has long been used by militaries and governments to facilitate secret communication. Encryption is now commonly used in protecting information within many kinds of civilian systems. It can be used to protect data "at rest", such as files on computers and storage devices (e.g. USB flash drives). In recent years there have been numerous reports of confidential data such as customers' personal records being exposed through loss or theft of laptops or backup drives. Encrypting such files at rest helps protect them should physical security measures fail. Digital rights management systems which prevent unauthorized use or reproduction of copyrighted material and protect software against reverse engineering (see also copy protection) are another somewhat different example of using encryption on data at rest.

Encryption is also used to protect data in transit, for example data being transferred via networks (e.g. the Internet, e-commerce), mobile telephones, wireless microphones, wireless intercom systems, Bluetooth devices and bank automatic teller machines. There have been numerous reports of data in transit being intercepted in recent years. Encrypting data in transit also helps to secure it as it is often difficult to physically secure all access to networks.

Encryption, by itself, can protect the confidentiality of messages, but other techniques are still needed to protect the integrity and authenticity of a message; for example, verification of a message authentication code (MAC) or a digital signature. Standards and cryptographic software and hardware to perform encryption are widely available, but successfully using encryption to ensure security may be a challenging problem. A single slip-up in system design or execution can allow successful attacks. Sometimes an adversary can obtain unencrypted information without directly undoing the encryption. See, e.g., traffic analysis, TEMPEST, or Trojan horse.

One of the earliest public key encryption applications was called Pretty Good Privacy (PGP). It was written in 1991 by Phil Zimmermann and was purchased by Network Associates (now PGP Corporation) in 1997.

Source: Wikipedia.

See also:


Note: conceptual questions about encryption might get more attention and better answers from the Crypto stack exchange.

36876 questions
65
votes
4 answers

Is Cipher thread-safe?

Quite simply, can one instance of javax.crypto.Cipher (e.g. Cipher.getInstance("RSA")) be used from multiple threads, or do I need to stick multiple of them in a ThreadLocal (in my case)?
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
65
votes
5 answers

Specified key is not a valid size for this algorithm

I have with this code: RijndaelManaged rijndaelCipher = new RijndaelManaged(); // Set key and IV rijndaelCipher.Key = Convert.FromBase64String("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678912"); rijndaelCipher.IV =…
user278618
  • 19,306
  • 42
  • 126
  • 196
65
votes
12 answers

What is the easiest way to encrypt a password when I save it to the registry?

Currently I'm writing it in clear text oops!, it's an in house program so it's not that bad but I'd like to do it right. How should I go about encrypting this when writing to the registry and how do I decrypt it? OurKey.SetValue("Password",…
Lisa
65
votes
6 answers

getting a IllegalBlockSizeException: Data must not be longer than 256 bytes when using rsa

I am using rsa key to encrypt a long string which I will send to my server(will encrypt it with server's public key and my private key) But it throws an exception like javax.crypto.IllegalBlockSizeException: Data must not be longer than 256 bytes I…
Ashwin
  • 12,691
  • 31
  • 118
  • 190
64
votes
6 answers

Best Practices for Passing Data Between Pages

The Problem In the stack that we re-use between projects, we are putting a little bit too much data in the session for passing data between pages. This was good in theory because it prevents tampering, replay attacks, and so on, but it creates as…
Brian MacKay
  • 31,133
  • 17
  • 86
  • 125
64
votes
7 answers

How can I hide or encrypt JavaScript code?

Is there any way to hide or encrypt JavaScript code to prevent people from viewing, copying, and/or modifying proprietary programs?
jasonGreen
63
votes
6 answers

new line appending on my encrypted string

In Main: public static void main(String[] args) throws NoSuchAlgorithmException { System.out.println("encrypt:" + encryptPassword("superuser")+":" ); } public static String encryptPassword(final String password) throws NoSuchAlgorithmException…
Rajesh Narravula
  • 1,433
  • 3
  • 26
  • 54
63
votes
3 answers

How to create a secure random AES key in Java?

What is the recommended way of generating a secure, random AES key in Java, using the standard JDK? In other posts, I have found this, but using a SecretKeyFactory might be a better idea: KeyGenerator keyGen =…
barfuin
  • 16,865
  • 10
  • 85
  • 132
63
votes
6 answers

Is it possible to hide/encode/encrypt php source code and let others have the system?

Is it possible to hide/encode/encrypt the php file/source code, and let others have the system installed and run on their machine?
Newbie
  • 2,775
  • 6
  • 33
  • 40
63
votes
7 answers

What is the best encryption library in C/C++?

What is the best encryption library in C/C++ In terms of: entropy quality ease of use readability portability performance What's your favorite and why do you like it?
oz10
  • 153,307
  • 27
  • 93
  • 128
62
votes
7 answers

SHA1 VS RSA: what's the difference between them?

What are the differences between SHA1 and RSA? Are they just different algorithms or are they fundamentally (i.e. used for different things) different on some level.
Ted Smith
  • 9,415
  • 16
  • 50
  • 52
62
votes
14 answers

Encrypting/Hashing plain text passwords in database

I've inherited a web app that I've just discovered stores over 300,000 usernames/passwords in plain text in a SQL Server database. I realize that this is a Very Bad Thing™. Knowing that I'll have to update the login and password update processes to…
Jonathan S.
  • 5,837
  • 8
  • 44
  • 63
61
votes
4 answers

Problems converting byte array to string and back to byte array

There are a lot of questions with this topic, the same solution, but this doesn't work for me. I have a simple test with an encryption. The encryption/decryption itself works (as long as I handle this test with the byte array itself and not as…
Bevor
  • 8,396
  • 15
  • 77
  • 141
61
votes
1 answer

How to transfer pgp private key to another computer?

I read this article (archived link) which explained very well how to setup PGP on macOS. But I'm planning to use the keys generated for signing Git commits, so I figure I need to transfer the keys to other computers. Is this correct? And, if so,…
erikvold
  • 15,988
  • 11
  • 54
  • 98
61
votes
12 answers

gpg decryption fails with no secret key error

I have a gpg .key file that is used as passphrase for decrypting a .dat.pgp file. The encrypted .data.pgp file gets successfully decrypted on one server with same .key file using following command cat xxx_gpg.key | /usr/bin/gpg --batch --quiet -o…
fortm
  • 4,066
  • 5
  • 49
  • 79