您正在打印字节数组本身,而不是其内容。您需要遍历数组以查看其包含的内容。
编辑:
还更改了getSalt以返回字节数组。从字节数组(使用新的String(salt))构造的String返回是不安全的,因为字节序列可能无法形成有效的String。
import java.security.*;public class Salt { public static void main(String[] args) throws NoSuchAlgorithmException { getSalt(); } private static byte[] getSalt() throws NoSuchAlgorithmException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] salt = new byte[16]; sr.nextBytes(salt); for(int i = 0; i<16; i++) { System.out.print(salt[i] & 0x00FF); System.out.print(" "); } return salt; }}


