Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

encription 1

Status
Not open for further replies.

Cagliostro

Programmer
Sep 13, 2000
4,226
GB
Hi,
could you give me please sample of password encription?
I want an algorithm what encript but can not decript.
If there are some classes I want a sample of using them.
Thanks,
Ion Ion Filipski
1c.bmp


filipski@excite.com
 
Here are some code samples I found while doing a search on the web...

I would suggest that you go to the following site to read up on this topic alittle bit more though..


Code:
   //true to encrypt, false to decrypt
   //k is the sipher
   public String messup(String s, int k, boolean encrypt)
   {
      int length = s.length();
      int end = (k>>>16)%length;
      int start = (end+1)%length;
      char key = (char)(k&0xFFFF);
      char [] result = new char[length];
      for(int i = start,j = 0;j<length;i=(i+1)%length,j++)
      {
         result<i> = (char)(s.charAt(i) ^ key);
         key = encrypt?result<i>:s.charAt(i);
      }
      return new String(result);
   }

**** Another Example ****

SecureRandom random = null;
	
try {
  random = SecureRandom.getInstance(&quot;SHA1PRNG&quot;, &quot;SUN&quot;);
} catch (NoSuchAlgorithmException nsae) {
  nsae.printStackTrace();
} catch (NoSuchProviderException nspe) {
  nspe.printStackTrace();
}

char[] message = new char[65536];
int[]  key     = new int[65536];

for(int i = 0; i < message.length; i++) {
  key<i> = random.nextInt(512);		
  message<i> ^= key<i>;
}
 
Thanks,
But is there any algorithm which can encrypt but may not decript? I mean password encription as it is performed in Unix. In OS Windows exists algorithm Md5. In database MySQL also exist function password(). If you want to see if it is the right password you encript it and compare with the encripted earlier and stored in the database one. There is no way to uncript it and makes no sence to crack tables with passwords. You are free too see all the passwords. Ion Filipski
1c.bmp


filipski@excite.com
 
I think you can always uncrypt if you know the algorithm used for encrypt, unless it uses a random function, but in that case you cannot compare with a password encripted earlier. Tell me if I'm wrong.
 
knowing the algorithm, doesn't mean you can uncrypt. One needs to know the key too.
 
thanks, I forgot about the key, but what I meant is that there is no algorithm that can encript but not uncript, if you know the rules (algorithm and key) used for the encription.
 
Ok,
If you know uncription algorithm it makes sence to try to guess the unkription key and/or to keep the passwords file for analising. So if you know only what an uncription algorithm exists make the password file the target of hacker attacks. I want an algorithm for password encriprion like MD5 in Windows or PASSWORD in MySQL, or password encription in Unix or something else without any uncription mechanismes.

Ion Filipski
1c.bmp


filipski@excite.com
 
MD5 is actually a HASH function and you do it in java like this:
public static byte[] getKeyedDigest(byte[] buffer, byte[] key) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(buffer);
return md5.digest(key);
} catch (NoSuchAlgorithmException e) {
}
return null;
}

[plug=shameless]
[/plug]
 
You can use a 'one-way' hashing function like MD5 to encrypt passwords. You simply store the MD5 encrypted form somewhere (database?) and when the user comes to log on, you MD5 encrypt their entry and compare it with the stored version.

There is no way to decrypt an MD5 hashed value. In theory, each possible hash value could be computed from an infinite set of starting values - it's a HASH. It is ideal for storing passwords as long as the original password does not need to be known.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top