Files

24 lines
1.8 KiB
Java

import ru.kusoft.qsafe.VaultCrypto;
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
/** Uses the actual Android crypto implementation, with synthetic data only. */
public class InteropFixture {
public static void main(String[] args) throws Exception {
Path directory=Paths.get(args[1]);Files.createDirectories(directory);
char[] password="Публичный тест 🔐 QSafe 2026".toCharArray();
if(args[0].equals("write")) {
String json="{\"format\":1,\"id\":\"interop-vault\",\"futureRoot\":{\"a\":1},\"entries\":[{\"id\":\"interop-card\",\"rev\":\"java-revision\",\"title\":\"Привет из Android 🔐\",\"notes\":\"Строка 1\\nСтрока 2\",\"fields\":[{\"name\":\"Пароль\",\"type\":\"password\",\"value\":\"Секрет & < >\",\"futureField\":true}],\"tags\":[\"Тест\"],\"attachments\":[{\"name\":\"test.txt\",\"data\":\"YWJj\"}],\"safeInCloudXml\":\"<card title='old'/>\"}]}";
try(VaultCrypto.Key key=VaultCrypto.create(password)) { Files.write(directory.resolve("java.qsafe"),VaultCrypto.encrypt(json.getBytes(StandardCharsets.UTF_8),key)); }
System.out.println("PASS Java generated Android-compatible fixture");
} else {
byte[] bytes=Files.readAllBytes(directory.resolve("dotnet.qsafe"));
try(VaultCrypto.Key key=VaultCrypto.unlock(bytes,password)) {
String json=new String(VaultCrypto.decrypt(bytes,key),StandardCharsets.UTF_8);
if(!json.contains("dotnet-revision")||!json.contains("attachments")||!json.contains("futureField"))throw new AssertionError("Lost data");
System.out.println("PASS Android Java decrypts Windows envelope with Unicode password and preserved metadata");
}
}
}
}