프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / Markus.Service.ConvertProcess / Exntensions / guid.cs @ 0caa0b73

이력 | 보기 | 이력해설 | 다운로드 (1.56 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Security.Cryptography;
5
using System.Text;
6
using System.Threading.Tasks;
7

    
8
namespace Markus.Service.Extensions
9
{
10
    public static class GuidExtension
11
    {
12
        public static Guid CreateUniqueGuid(this Guid guid)
13
        {
14
            return GetUniqueGuid();
15
        }
16

    
17
        private static Guid GetUniqueGuid()
18
        {
19
            char[] chars = "ABCDEF1234567890".ToCharArray();
20
            byte[] data = new byte[1];
21
            System.Security.Cryptography.RNGCryptoServiceProvider crypto = new System.Security.Cryptography.RNGCryptoServiceProvider();
22
            crypto.GetNonZeroBytes(data);
23
            data = new byte[32];
24
            crypto.GetNonZeroBytes(data);
25
            StringBuilder result = new StringBuilder(32);
26

    
27
            foreach (byte b in data)
28
            {
29
                result.Append(chars[b % (chars.Length - 1)]);
30
            }
31

    
32
            return Guid.ParseExact(result.ToString(0, 8) + "-" + result.ToString(8, 4) + "-" + result.ToString(11, 4) + "-"
33
                + result.ToString(16, 4) + "-" + result.ToString(20, 12), "D");
34
        }
35

    
36
        public static string shortGuid()
37
        {
38
            byte[] numArray = new byte[16];
39
            using (RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create())
40
                randomNumberGenerator.GetBytes(numArray);
41
            return Convert.ToBase64String(new Guid(numArray).ToByteArray()).Substring(0, 10).Replace("/", "").Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
42
        }
43
    }
44
}
클립보드 이미지 추가 (최대 크기: 500 MB)