Reverse certificate DN

106 Views Asked by At

could someone please assist me with reversing the DN of a certificate. (I have never used perl before so I don't know what the best practices are).

I have the following string:

$issuer = "DC=ORG,DC=OpenXPKI,OU=Test CA,CN=CA ONE";

And I would need this:

$issuer = "CN=CA ONE,OU=Test CA,DC=OpenXPKI,DC=ORG";
1

There are 1 best solutions below

1
Sobrique On BEST ANSWER

I'd do it like this:

$issuer = join ",", reverse split (/,/, $issuer);

split your string on commas, reverse the ordering, and then join them back together (with commas)