001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: Base64ToHex.java,v 1.2 2008/06/25 05:47:33 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.saml.common; 030 031import com.sun.identity.shared.encode.Base64; 032 033/** 034 * This class <code>Base64ToHex</code> is used to convert Base64 encoded 035 * SAML source ID to Hex encoded ID. 036 * @supported.all.api 037 */ 038 039public class Base64ToHex { 040 041 /** 042 * Returns Hex encoded source ID based on the input Base64 source ID. 043 * <br>Usage: java com.sun.identity.saml.common.Base64ToHex <Base64_encoded_id><br> 044 * This method will print out Hex encoded source ID to the standard 045 * output. 046 * 047 * @param args Hex encoded source ID. 048 */ 049 050 public static void main(String args[]) throws Exception { 051 052 if (args.length != 1 ) { 053 System.out.println("Usage: java Base64ToHex <Base64_encoded_id>"); 054 return; 055 } 056 057 String inputString = args[0]; 058 Base64 decoder = new Base64(); 059 byte[] byteArray = decoder.decode(inputString); 060 int readBytes = byteArray.length; 061 StringBuffer hexData = new StringBuffer(); 062 int onebyte; 063 for (int i=0; i < readBytes; i++) { 064 onebyte = ((0x000000ff & byteArray[i]) | 0xffffff00); 065 hexData.append(Integer.toHexString(onebyte).substring(6)); 066 } 067 System.out.println(hexData.toString()); 068 } 069}