1

Edits: I reworded this question.

I notice that at YouTube, each video has a unique string such as 1cru2fzUlEc to identify itself.

I am wondering how I can do the same thing efficiently in Java.

Thanks for any input.

Cheers!

Mehraban
  • 3,164
  • 4
  • 37
  • 60
curious1
  • 14,155
  • 37
  • 130
  • 231
  • 1
    possible duplicate of [How do I create a unique ID in Java?](http://stackoverflow.com/questions/1389736/how-do-i-create-a-unique-id-in-java) – om-nom-nom Apr 17 '13 at 13:52
  • The reworded question is a possible duplicate of http://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string-in-java – Patashu Apr 17 '13 at 13:55
  • om-nom-nom and Patashu, thanks for the links, which is quite helpful. – curious1 Apr 17 '13 at 16:46

3 Answers3

3

As Patashu already pointed out: These strings are not encrypted they are simply unique identifiers which cannot be guessed or calculated.

This can be achieved in Java using the UUID implementation. These UUIDs are longer than youtube's but the principle is the same.

The security of these UUIDs should be good enough for almost all occasions, as has been discussed here.

Community
  • 1
  • 1
korius
  • 359
  • 2
  • 6
3

with apache commons-lang

import org.apache.commons.lang.RandomStringUtils;

public static final int ID_LENGTH = 11;

public String generateUniqueId() {
    return RandomStringUtils.randomAlphanumeric(ID_LENGTH);
}
Paul Henry
  • 355
  • 3
  • 9
2

Sites such as youtube don't 'encrypt' the identifier of a video. When the video is made it generates a random string for it, and that random string (after making sure it is unique) IS the video's identifier.

Patashu
  • 21,443
  • 3
  • 45
  • 53