Millions saw the apple fall, but Newton asked why.
Also i see 1 more issue, you have used same "file" instance for both input and output stream(Line 64-66 and 40-42). You should use different instance.
Problem is with your keys. I suppose it is calculating same values for your given keys. Try to use different keys.
Millions saw the apple fall, but Newton asked why.
Mandar Khire wrote:
1. How 2 different keys works in DES Encryption-Decryption?
With DES, you can actually "decrypt" plain text and you will get a cipher text. This text is not readable, until you "encrypt" it back to plain text.
So, when you encrypt with one key and then "decrypt" with a second key, you are effectively encrypting twice. To get back the original plain text, you will need to encrypt with the second key, and then decrypt with the first key (reversing the process).
In symmetric-key schemes,[3] the encryption and decryption keys are the same. Communicating parties must have the same key before they can achieve secure communication.
The Data Encryption Standard was once a predominant symmetric-key algorithm for the encryption of electronic data.
.Controversies arose out of classified design elements, a relatively short key length of the symmetric-key block cipher design, and the involvement of the NSA, nourishing suspicions about a backdoor.
Millions saw the apple fall, but Newton asked why.
For proper message encryption you will want to use an AEAD algorithm, such as AES-GCM.
This is important: Encryption and authentication are closely related. Don't encrypt without authentication!
Millions saw the apple fall, but Newton asked why.
Mandar Khire wrote:I change my code for 'AES'
[...]
What is authentication in above examples? Did i miss it?
Which Algorithm should i use when i want to use key length is 26 characters?
.You're directly using your passwords as key material. This is bad. You should use a key factory that transforms passwords to secret keys. First, use a PBEKeySpec to generate the key material, and then transform that key material to an AES key. You should also never use String to store passwords. Use char[] or byte[] arrays.
Millions saw the apple fall, but Newton asked why.
That's logical, because you're generating a new key for each operation. You need to generate a key only once, and reuse that key if you want to decrypt any message encrypted with that key.
- Who is going to encrypt?
- Who is going to decrypt?
- How are you going to share the secret between these two parties? (Remember, a secret is secret, so don't use predictable data such as hardware IDs.)
- How are you going to store the secret between sessions? (Key stores or enter password every time?)
Once the sensitive data is in the form of a String, you have already lost.
- It doesn't matter whether it's an UUID or user input, a variable amount of characters should be considered a password, and an actual secret key should be derived from that.
- You are not using the IV properly. THIS IS A HUGE SECURITY FLAW. The IV should be unique for every encryption operation.
I suggest you read up on block ciphers, initialization vectors, symmetric keys, message authentication and good cryptography practices in general. If you don't understand why you're writing a particular line of code, you're probably breaking security.
Millions saw the apple fall, but Newton asked why.
Mandar Khire wrote:I just give you small hint of my logic (HDD etc), other 4 to 5 factors i used for generate sensitive data.
Then I Encrypt my sensitive data with SHA-512. It generate 128 character string, from it i just use 24 characters.
(These 26 also i pick with one another logic which randomly chose it. out of 128.)
So as per my requirements, i think that i use more complexity for picking string for security key. Now from your example i used more complexity to generate 'Security key'.
This also not sufficient to secure a 'security key'?
I found link which shows CipherInputStream for AEAD modes is insecure in JDK7 (GCM, EAX, etc.)
If this is true, then which other Algorithm i should use for more secure my 'hello.txt'.
I really don't understand this....
Why are you even using hardware IDs and other factors?
Don't mess with primitives like SHA-512!
If it hasn't, stop using CipherInputStream, and just use Cipher directly. You're not using CipherInputStream like a stream anyway.
Why is iv static?
- Why is tagLength static?
- Why are you using securitykey2? Symmetric algorithms require one key.
- Why are you storing the password (Yes, you're using "D0A81F-E11293-4B5D29-BCEC1" as a password) as a String?
- Why are you using String for paths, and not Path?
- Why are you constructing a Message without using it?
- Why are you storing the key in the message (THIS IS BAAAAD).
- Why are you using buffers if you're working with streams?
- Why are you not using try-with-resources for your streams?
f you want to encrypt an entire file, you need to think about the file format of your encrypted file.
AES-GCM will only store the cipher text and the authentication tag. You still need to store the initialization vector, and possibly other header information (like the algorithm used, the algorithm parameters, etc.)
Millions saw the apple fall, but Newton asked why.
Mandar Khire wrote:My aim is example PC A has app & it will has product key by that i will give License key to user. Now if i can store that info in some file, i should encrypt it & hide it.
Whenever i have to cross verify license, i will decrypt that file, fetch data & cross verify it.
Now if i copy this hidden & encrypted file, paste it into PC B, by thought of cracking license, it should give me error. So i use Hardware based some key.
I not depend on 1 hardware, i take 4-5 things which very essential for pc.
Each give me some data & each data i encrypt with some logic with different algorithm. So i try to make complex to get license key.
Don't mess with primitives like SHA-512!
f you want to encrypt an entire file, you need to think about the file format of your encrypted file.
AES-GCM will only store the cipher text and the authentication tag. You still need to store the initialization vector, and possibly other header information (like the algorithm used, the algorithm parameters, etc.)
Don't get me started about those stupid light bulbs. |