ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Having problem decoding base64 back to string?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Having problem decoding base64 back to string?

    Hello,

    Im using java to (try) to decode from a base64 url querystring.

    I have been sent a (supposed to be) base64 code that I have to decode.

    But I cant seem to decode the base64 code back to a string.

    This is a test program:


    Code:
    public class AES {                                                          
      static String IV = "xxxYYYzzz01234xxt"; (not the actual code Im using.)                            
      static String Key = "aaaBBBcccDDDD;  (not the actual code Im using.)            
                                                                                
      public static void main(String [] args) {                                 
                                                                                
        byte[] encodedIV = IV.getBytes();                                       
        byte[] encodedKey = Key.getBytes();
                                                                    
       System.out.println("===== Encoded String =====");           
       System.out.println("Original String IV: " + IV );           
       System.out.println("Original String Key: " + Key);          
       System.out.println(" ");                                    
                                           
       //decoding byte array into base64                            
       System.out.println("===== decode IV =====");                 
       byte[] decodedIV = Base64.decodeBase64(encodedIV);           
       System.out.println("===== decode Key =====");                
       byte[] decodedKey = Base64.decodeBase64(encodedKey);;        
                                                                    
                                                                               
        String stringIV = new String(decodedIV);                               
        String stringKey = new String(decodedKey);                             
        System.out.println("===== Decoded String =====");                      
        System.out.println("decodedIV String : " + new String(stringIV));      
        System.out.println("decodedKey String : " + new String(stringKey));    
      }                                                                        
                                                                               
    }
    Results:


    ===== decode IV =====
    ===== decode Key =====
    ===== Decoded String =====
    decodedIV String : Æ$þÒéñe_Y³;7UÓ d
    decodedKey String : ²LÆPT W 08=siL!9L < NÂr Q î
    þÝ

  • #2
    Re: Having problem decoding base64 back to string?

    The example you provided does not have a base64 encoded string. I know you said "these aren't the actual strings", but the ones you provided are not base64, either. So either you've provided a very bad example, or the data isn't base64 encoded to begin with.

    Your output is also clearly not base64 encoded (which is expected). But, you don't say what's wrong with it? Is there a problem with the output?

    Comment


    • #3
      Re: Having problem decoding base64 back to string?

      Im actually trying to use base64 AES encryption. But they are "supposed" to be a IV and encryptionkey, But they are not converting from base64.

      I was thinking my byte[] to string wasnt correct, but I think it is. I just want to be positive about this before I go back to the client.

      Comment


      • #4
        Re: Having problem decoding base64 back to string?

        Originally posted by davisty View Post
        Im actually trying to use base64 AES encryption. But they are "supposed" to be a IV and encryptionkey, But they are not converting from base64.
        They look to me like they ARE converting from base64. Can you explain why you think they are not?

        Comment


        • #5
          Re: Having problem decoding base64 back to string?

          Because they told me they not.
          Last edited by davisty; June 13, 2014, 06:40 AM.

          Comment


          • #6
            Re: Having problem decoding base64 back to string?

            clost ticket

            Comment

            Working...
            X