gpt4 book ai didi

java - 如何配置MongoDB字段级加密?

转载 作者:行者123 更新时间:2023-12-02 01:35:57 26 4
gpt4 key购买 nike

我尝试使用MongoDB在4.2版本中提供的字段级加密。但我遇到了一些错误。

Caused by: java.lang.UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序。

at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:278)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)
at com.sun.jna.Native.register(Native.java:1722)
at com.mongodb.crypt.capi.CAPI.<clinit>(CAPI.java:759)
at com.mongodb.crypt.capi.MongoCryptImpl.<init>(MongoCryptImpl.java:91)
at com.mongodb.crypt.capi.MongoCrypts.create(MongoCrypts.java:36)
at com.mongodb.client.internal.Crypts.createCrypt(Crypts.java:35)
at com.mongodb.Mongo.<init>(Mongo.java:328)
at com.mongodb.Mongo.<init>(Mongo.java:313)
at com.mongodb.Mongo.<init>(Mongo.java:309)
at com.mongodb.MongoClient.<init>(MongoClient.java:328)

然后我将 jdk 修改为 32 位,又收到另一个错误消息。

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\longf\AppData\Local\Temp\jna-103156074\jna6619363862608272389.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:947)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922)
at com.sun.jna.Native.<clinit>(Native.java:190)
at com.mongodb.crypt.capi.CAPI.<clinit>(CAPI.java:759)
at com.mongodb.crypt.capi.MongoCryptImpl.<init>(MongoCryptImpl.java:91)
at com.mongodb.crypt.capi.MongoCrypts.create(MongoCrypts.java:36)
at com.mongodb.client.internal.Crypts.createCrypt(Crypts.java:35)
at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:70)
at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:61)
at com.mongodb.client.MongoClients.create(MongoClients.java:114)
at com.mongodb.client.MongoClients.create(MongoClients.java:50)
OS: Windows 10
MongoDB version: 4.2.0
mongo-java-driver: 3.11.0
mongodb-crypt: 1.0.0-beta4
        System.setProperty("jna.prefix", "win32-x86-64");

final byte[] localMasterKey = new byte[96];
new SecureRandom().nextBytes(localMasterKey);

Map<String, Map<String, Object>> kmsProviders = new HashMap<String, Map<String, Object>>() {{
put("local", new HashMap<String, Object>() {{
put("key", localMasterKey);
}});
}};

String keyVaultNamespace = "admin.datakeys";

AutoEncryptionSettings autoEncryptionSettings = AutoEncryptionSettings.builder()
.keyVaultNamespace(keyVaultNamespace)
.kmsProviders(kmsProviders)
.build();

MongoClientSettings clientSettings = MongoClientSettings.builder()
.autoEncryptionSettings(autoEncryptionSettings)
.build();

MongoClient mongoClient = MongoClients.create(clientSettings);
MongoCollection<Document> collection = mongoClient.getDatabase("test").getCollection("coll");
collection.drop(); // Clear old data

collection.insertOne(new Document("encryptedField", "123456789"));

System.out.println(collection.find().first().toJson());

https://mongodb.github.io/mongo-java-driver/3.11/driver/tutorials/client-side-encryption/#mongocryptd-configuration

更新

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

错误:

Caused by: java.lang.UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序。
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) Client VM (build 25.221-b11, mixed mode)

错误:

Can't load AMD 64-bit .dll on a IA 32-bit platform

最佳答案

应用程序似乎正在尝试加载像“.dll”这样的 native 库,并且该库不存在于 PATH 环境变量和 java.library.path 系统属性的路径中。请检查 System.loadLibrary 方法中传递的值是否正确以及该库是否确实存在。此外,您可以尝试提供库的绝对路径。

关于java - 如何配置MongoDB字段级加密?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57519964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com