JNA version: 5.8.0
jna-platform.jar (+ jna.jar)
Java Version: 1.8.0_261
java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
OS Version: Windows 10
Microsoft Windows [Version 10.0.18363.1556]
Description of the problem
The method Crypt32Util.cryptProtectData is not able to encrypt zero-length array. Please note that .NET ProtectedData.Protect and direct Windows API CryptProtectData accept and encrypt zero-length data perfectly.
Code that reproduces the bug
import com.sun.jna.platform.win32.Crypt32Util;
import com.sun.jna.platform.win32.WinCrypt;
public class JNACryptProtectDataBug {
public static void main(String[] args) {
byte[] data = {};
byte[] encrypted = Crypt32Util.cryptProtectData(data, WinCrypt.CRYPTPROTECT_UI_FORBIDDEN);
System.out.println("ok");
}
}
Expected
Actual
Exception in thread "main" java.lang.IllegalArgumentException: Allocation size must be greater than zero
at com.sun.jna.Memory.<init>(Memory.java:239)
at com.sun.jna.platform.win32.WinCrypt$DATA_BLOB.<init>(WinCrypt.java:75)
at com.sun.jna.platform.win32.Crypt32Util.cryptProtectData(Crypt32Util.java:80)
at com.sun.jna.platform.win32.Crypt32Util.cryptProtectData(Crypt32Util.java:60)
at JNACryptProtectDataBug.main(JNACryptProtectDataBug.java:7)
JNA version: 5.8.0
jna-platform.jar (+ jna.jar)
Java Version: 1.8.0_261
java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
OS Version: Windows 10
Microsoft Windows [Version 10.0.18363.1556]
Description of the problem
The method
Crypt32Util.cryptProtectDatais not able to encrypt zero-length array. Please note that .NETProtectedData.Protectand direct Windows APICryptProtectDataaccept and encrypt zero-length data perfectly.Code that reproduces the bug
Expected
Actual