小编jar*_*rok的帖子

Java AES CTR IV和计数器

我试着找到答案,自己看这里并在别处搜索了一段时间,但我还是有一些问题.

假设这个Java代码:

try
{   
    int cipherMode = Cipher.ENCRYPT_MODE;

    SecretKeySpec secretKey = ...; // generated previously using KeyGenerator       

    byte[] nonceAndCounter = new byte[16];
    byte[] nonceBytes      = ...; // generated previously using SecureRandom's nextBytes(8);

    // use first 8 bytes as nonce
    Arrays.fill(nonceAndCounter, (byte) 0);
    System.arraycopy(nonceBytes, 0, nonceAndCounter, 0, 8);

    IvParameterSpec ivSpec = new IvParameterSpec(nonceAndCounter);
    Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");

    cipher.init(cipherMode, secretKey, ivSpec);

    File inFile  = new File(...);
    File outFile = new File(...);

    long bytesRead = 0;

    try (FileInputStream is = new FileInputStream(inFile);
         FileOutputStream …
Run Code Online (Sandbox Code Playgroud)

java encryption aes initialization-vector

4
推荐指数
1
解决办法
5810
查看次数

标签 统计

aes ×1

encryption ×1

initialization-vector ×1

java ×1