String转byte[]
byte[] sInput = new byte[0]; try { // 可以指定编码,默认也只UTF-8 sInput = "这是内容".getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }
byte[]转String
// 这里sInput是上面byte[],也是可以指定编码,默认也是UTF-8 String str = new String(sInput, "UTF-8")
byte[]打印到控制台看
org.bouncycastle.pqc.math.linearalgebra.ByteUtils.toBinaryString(sInput) // 这个方法的源码 public static String toBinaryString(byte[] var0) { String var1 = ""; for(int var2 = 0; var2 < var0.length; ++var2) { byte var3 = var0[var2]; for(int var4 = 0; var4 < 8; ++var4) { int var5 = var3 >>> var4 & 1; var1 = var1 + var5; } if (var2 != var0.length - 1) { var1 = var1 + " "; } } return var1; }