- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
c# donet 可以为以下 java 代码生成相同的 UUID 吗?如果是这样怎么办?我试过 GUID 但没有用!
文本:
String cleartext = "CN=CompanyName;mac=some mac;@host=somehost;email=admin@somedomain.com;issued=01/01/20013;expire=12/12/2013";
Java代码:
UUID uuid = UUID.nameUUIDFromBytes(cleartext.getBytes("UTF-8"));
C#代码:
byte[] b = System.Text.Encoding.UTF8.GetBytes(cleartext);
Guid uid = new Guid(b);
Console.Write(uid.ToString());
引用文献 Earlier discussions
最佳答案
如果您只需要相同的 UUID 字符串(而不是实际的 UUID/Guid 对象),此 C# 方法将返回与 Java 的 UUID.nameUUIDFromBytes(byte[])
方法相同的值。
public static string NameUUIDFromBytes(byte[] input)
{
MD5 md5 = MD5.Create();
byte[] hash = md5.ComputeHash(input);
hash[6] &= 0x0f;
hash[6] |= 0x30;
hash[8] &= 0x3f;
hash[8] |= 0x80;
string hex = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
return hex.Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-");
}
C# 示例
string test = "test";
Console.Out.WriteLine(NameUUIDFromBytes(Encoding.UTF8.GetBytes(test)));
Output:
098f6bcd-4621-3373-8ade-4e832627b4f6
Java 示例
UUID test = UUID.nameUUIDFromBytes("test".getBytes("UTF-8"));
System.out.println(test);
Output:
098f6bcd-4621-3373-8ade-4e832627b4f6
编辑:我知道这是事后的,但这会产生一个具有相同值的实际 Guid
对象。以防万一有人想要它。
public static Guid NameGuidFromBytes(byte[] input)
{
MD5 md5 = MD5.Create();
byte[] hash = md5.ComputeHash(input);
hash[6] &= 0x0f;
hash[6] |= 0x30;
hash[8] &= 0x3f;
hash[8] |= 0x80;
byte temp = hash[6];
hash[6] = hash[7];
hash[7] = temp;
temp = hash[4];
hash[4] = hash[5];
hash[5] = temp;
temp = hash[0];
hash[0] = hash[3];
hash[3] = temp;
temp = hash[1];
hash[1] = hash[2];
hash[2] = temp;
return new Guid(hash);
}
关于c# - UUID 与 c# 代码互操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18021808/
我试图再次将反射的 UUID 转换回实际的 UUID 对象,但找不到方法,当我打印反射值时它看起来是正确的,但在尝试转换时我找不到方法。 package main import ( "fmt"
我想知道 UUID 是否是唯一的,即使它们是在不同的系统上生成的,这些系统可能采用不同的算法。例如,如果您在 MySQL 和 .Net 中生成了一堆 UUID,碰撞的可能性会更高,还是所有系统都使用完
是否可以一个接一个地创建两个重复的 UUID?我不熟悉 UUID 是如何生成的,但我猜想如果您在同一毫秒内从同一 MAC 地址创建了两个单独的 UUID,那么它们将完全相同。这是真的吗? 我想我是在问
当我使用 python uuid 模块中的 UUID() 函数检查我们的测试 uuid 之一时,我遇到了这种奇怪的行为。 从 uuid 导入 UUID uuid1 = UUID('00000000-0
开始使用 java.util.UUID。我的问题是如果我有两个 UUID 变量,比如 u1 和 u2,并且我想检查它们是否相等,我可以安全地使用表达式 u1 == u2 还是必须编写 u1 .equa
我浏览了 python UUID 模块的文档。 >>> uuid.uuid4() UUID('82fe5629-6680-4b13-a4e3-7a082f10e038') >>> uuid.uuid4
我正在创建一个程序,我在其中大量使用 UUID 来识别用户和组等内容。鉴于 UUID 已经被占用的可能性极低,我是否应该担心发生碰撞的可能性? 最佳答案 这在很大程度上取决于 A)您的要求 B)底层实
您应该使用哪个版本的 UUID?我看到很多帖子解释了每个版本的含义,但我很难弄清楚什么最适合哪些应用程序。 最佳答案 有两种不同的方式生成 UUID。 如果您只需要一个唯一 ID,则需要版本 1 或版
我知道我们可以轻松提取 uuid 版本号。有没有可靠的方法来提取时间戳、MAC 地址等信息? 谢谢! 最佳答案 符合标准的 UUID 可能是多种变体之一,它看起来像这样: AAAAAAAA-BBBB-
我可以干净地使用私有(private) UUID 变体/版本吗? 我使用我基本上认为是大整数的随机 UUID。现在,我想生成一个“私有(private)”UUID,它不基于众所周知的 5 个变体/版本
我已阅读 man 页面,但我不明白 name 和 namespace 的用途。 For version 3 and version 5 UUIDs the additional command lin
我目前正在项目中使用 boost::uuids::uuid,并且我想序列化包含 boost::uuids::uuid 的对象。我尝试了下面的简单示例,但出现错误: /usr/include/boost
我正在使用 Datastax Java 驱动程序在 Cassandra 数据库中执行基本的插入语句。我的主键列是uuid类型。从我在官方文档中看到的,在 Cassandra 中调用 uuid() 函数
会抛出异常吗? UUID() 是否会悄无声息地失败?是否有任何情况下“myStatus”来自 myStatus = True myUUID = uuid.UUID( someWeirdValue )
在我的 Android 应用程序中,我有这种采用 UUID 的方法。不幸的是,当我这样做时: OverviewEvent overviewevent = eventAdapter.getOvervie
我有一个简单的 mongo 迁移框架,它正在执行一些传递给它的脚本。 现在我想将我的 LUUID 迁移到 UUID。我写了以下内容: function fixIds(collectionName) {
我有一个非常奇怪的问题是我得到一个有效的 UUID 不是一个有效的 UUID,例如: 'fd31b6b5-325d-4b65-b496-d7e4d16c8a93' is not a valid UUI
我正在测试 Goa对于一个 API。我想使用 uuid 作为 ID 数据类型。我在 controller.go 中修改了以下函数: // Show runs the show action. func
我有一个包含 uuid 和系统列的表。我需要一个查询来仅返回具有 system=1 的 uuid,而不返回具有 system= 1 和 2 的 uuid 最佳答案 SELECT * FROM
我很想了解在 Avro 中编码一种非常特定类型的数据的最佳实践:UUID。 最佳答案 到目前为止,我发现的唯一方法是定义自定义 UUID: { "namespace" : "your.namesp
我是一名优秀的程序员,十分优秀!