ArrayIndexOutOfBoundsException in bouncycastle.util.Strings.fromUTF8ByteArray

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ArrayIndexOutOfBoundsException in bouncycastle.util.Strings.fromUTF8ByteArray

Lou Wynn

Hi BC Devs,

The following code generates the Exception:

import java.util.Base64;
import org.bouncycastle.util.Strings;

public class BCStrings {

    public static void main(String[] args) {
        byte[] s = Base64.getDecoder().decode("dCiPcOC1P+U4h6QeSw+8d4+3k4SNKhnT");
        String bcStr = Strings.fromUTF8ByteArray(s);
    }
}



-- 
Thanks,
Lou
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ArrayIndexOutOfBoundsException in bouncycastle.util.Strings.fromUTF8ByteArray

Matti Aarnio
Hi Lou,

Given that your Base64 encoded data does not contain valid UTF-8 byte stream, the Exception is very much of an expected result.

$ echo "dCiPcOC1P+U4h6QeSw+8d4+3k4SNKhnT"|base64 -d -i |od -tx1
0000000 74 28 8f 70 e0 b5 3f e5 38 87 a4 1e 4b 0f bc 77
0000020 8f b7 93 84 8d 2a 19 d3

https://en.wikipedia.org/wiki/UTF-8




On 06/17/2017 12:30 PM, Lou Wynn wrote:

Hi BC Devs,

The following code generates the Exception:

import java.util.Base64;
import org.bouncycastle.util.Strings;

public class BCStrings {

    public static void main(String[] args) {
        byte[] s = Base64.getDecoder().decode("dCiPcOC1P+U4h6QeSw+8d4+3k4SNKhnT");
        String bcStr = Strings.fromUTF8ByteArray(s);
    }
}



-- 
Thanks,
Lou



smime.p7s (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ArrayIndexOutOfBoundsException in bouncycastle.util.Strings.fromUTF8ByteArray

Lou Wynn

I see. Thanks for the quick response.

Thanks,
Lou
On 06/17/2017 02:48 AM, Matti Aarnio wrote:
Hi Lou,

Given that your Base64 encoded data does not contain valid UTF-8 byte stream, the Exception is very much of an expected result.

$ echo "dCiPcOC1P+U4h6QeSw+8d4+3k4SNKhnT"|base64 -d -i |od -tx1
0000000 74 28 8f 70 e0 b5 3f e5 38 87 a4 1e 4b 0f bc 77
0000020 8f b7 93 84 8d 2a 19 d3

https://en.wikipedia.org/wiki/UTF-8




On 06/17/2017 12:30 PM, Lou Wynn wrote:

Hi BC Devs,

The following code generates the Exception:

import java.util.Base64;
import org.bouncycastle.util.Strings;

public class BCStrings {

    public static void main(String[] args) {
        byte[] s = Base64.getDecoder().decode("dCiPcOC1P+U4h6QeSw+8d4+3k4SNKhnT");
        String bcStr = Strings.fromUTF8ByteArray(s);
    }
}



-- 
Thanks,
Lou



Loading...