为服务媒体项目(照片、mp3、文档等)生成密钥的最佳实践

发布于 2024-09-11 00:06:04 字数 624 浏览 3 评论 0原文

我正在制作一个 P2P 媒体共享功能,用户可以与其他人共享文件(图像、mp3 等)。当用户与其他用户共享文件时,我只需向他们发送该文件的链接即可。链接如下所示:

http://www.domain.com/file?q=unique_key

现在,unique_key 必须是字母数字且不易猜测,因此我计划使用文件记录的编码密钥。

这在我之前的Python GAE应用程序中很容易,但在我的新Java应用程序中,我无法获取这个键值,我得到的只是一个长ID(数字)。

我的实体有一个名为 ID 的字段,该字段很长,但在我的 GAE 管理控制台中有一个实体编码密钥,它是字母数字,我希望这对于我的数据库中的每条记录都是唯一的。那么如何访问呢?

我正在使用 Objectify,当我创建一个像这样的新密钥时

Key myKey = new Key (FileEntity.class,EntityID);

myKey 是一个字符串,其中包含一些文本,但它是我正在寻找的 uniqye 字母数字 id。

抱歉我的问题很模糊,请帮忙。

I am making a P2P Media sharing feature where users can share Files (images, mp3 etc) with others. When a User shares a file with the other I simply send them the link to that file. The links looks like:

http://www.domain.com/file?q=unique_key

Now, the unique_key must be alpha-numeric and not easily guessable, so i plan to use the file record's encoded key.

This was easy in my earlier Python GAE App, But in my new Java App, I am unable to get hold of this Key value, all i get is an ID which is Long (numeric).

My Entity has a field called ID which is Long, but in my GAE Admin console there is a entity encoded key which is alpha numeric, and I hope thats unique for every record in my database. So how to access that?

I am using Objectify and when i create a new key like this

Key myKey = new Key (FileEntity.class, entityID);

myKey is a string with some text in it, but its the uniqye alpha numeric id that I am looking for.

Sorry for my fuzzy question, please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老子叫无熙 2024-09-18 00:06:05

编码的字符串键很容易被猜到 - 它们是包含应用 ID、种类名称和 ID 的编码协议缓冲区。如果您需要不易猜测的值,我建议生成 UUID,并使用它们作为键名称(字符串键)。

Encoded string keys are easily guessible - they're encoded protocol buffers containing the app ID, kind name, and ID. If you need values that aren't easily guessable, I would recommend generating UUIDs, and using those as key names (string keys), instead.

负佳期 2024-09-18 00:06:05

由于您使用的是 objectify,因此您可以使用以下方法获取字符串编码的密钥

ObjectifyService.factory().keyToString( myKey );

Since you are using objectify, you can get the string encoded key by using the method

ObjectifyService.factory().keyToString( myKey );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文