java - How to pass unsigned bytes to SecretKeySpec()? -
i need use java's secretkeyspec() array of numbers greater 127.
if following:
new byte[] { (byte)0xd9, (byte)0xdf, (byte)0x85 } the numbers converted bytes , they'll negative.
of course can & them 0xff , save them in short array , save value, won't able pass array secretkeyspec(), because receives bytes[] array.
any ideas?
this rendering issue. secretkeyspec works byte array, , have no problem constructing byte array. question how represent large (>127) integers java bytes, or equivalently, mean '217' byte.
you use whatever mapping want, java has pretty natural choice - convert integer byte, use cast, (byte)i, , convert back, use byte.tounsignedint(b). can see, recovers original values:
public static void main( string[] args ) { (int count = 0; count<256; count++){ system.out.println(count+" : "+(byte)count+" => "+byte.tounsignedint((byte)count)); } }
Comments
Post a Comment