Srini G
Srini G

Reputation: 11

How can i find in java program, whether the given string is encrypted string or not?

For exmple, am giving the string like "u8tyuy8+==" (this is encrypted string using bouncy castle) to java.. i need to do validation like whether the given string is encrypted string or not? is there any method exist in java?

Upvotes: 0

Views: 683

Answers (1)

Stephen C
Stephen C

Reputation: 719289

It is theoretically impossible to say if a given String has been encrypted. The best you could do would be to tell if it could have been encrypted. Even then, it depends on knowing the encryption scheme(s) (and armoring1 scheme(s)) that could have been used.

As RealSkeptic points out, a better approach would be to record (in your database) whether or not the string has been encrypted, and (if necessary) which schemes have been used for encrypting and armoring the data.


@Bucket comments:

There's no risk in attempting to decrypt if there's no unequivocal way to tell if it is encrypted.

Yes, there is no risk in trying. (Especially if you catch any possible exceptions.) However, the flipside is that there is no unequivocal way of telling if you have successfully decrypted the string2, so there is not a lot to be achieved by doing this.


1 - I am guessing based on the example string that the original data has been encrypted, and then encoded as ASCII using Base64 encoding ... or something similar.

2 - ... unless you also have the original unencrypted version of the data to compare against.

Upvotes: 2

Related Questions