What is the algorithm used to create the "Tiny links"


I've seen this question: Is there a way to get a Confluence page's tiny link programmatically? and I have one in a similar vein.

What is the algorithm used to create the tiny links?

I'm assuming it's some kind of base 64/62 encoder of some sort? If anyone knows where in the source to look for the code, a path would be greatly appreciated.


4 answers

1 accepted

3 votes
Accepted answer
David Simpson Community Champion Sep 17, 2012

Check out the source of com.atlassian.confluence.pages.TinyUrl...


id is the pageId.

I used the following functions in PHP based on the Steve's code:

function id2tinylink($id)
    $bytes = pack("L", (int)$id);  // convert the long to bytes
    return rtrim($base64string_escaped, "A=");

function tinylink2id($tinylink){
    $base64string_encoded = str_pad($tinylink, 8, "A", STR_PAD_RIGHT);
    $base64string = strtr($base64string_encoded, '_-', '+/');
    $bytes = base64_decode($base64string);
    return unpack("L",$bytes)[1];

If anyone would like to emulate this functionality in PHP for whatever reason:

function tinylinkid($id)
	$bytes = pack("L", $id);  // convert the long to bytes
	$bytes = rtrim($bytes);  // trim any null characters
	$bytestring = "";
	$len = strlen($bytes); 
	for($i = 0; $i < $len; $i++) {
		$bytestring = $bytestring . $bytes[$i]; // build the byte string
	$base64string = base64_encode($bytestring); // base64 encode the byte string
	$base64string = rtrim($base64string, "="); // trim any base64 padding characters
	return $base64string;

Thanks for David for the pointer.


Could you describe a method of decoding?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

68 views 3 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you