示例#1
0
        private int CreateSsrc(string hostName)
        {
            try
            {
                ObjectIDGenerator obGen = new ObjectIDGenerator();

                MessageDigest md = MessageDigest.GetInstance("MD5");
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Convert.ToString(new Date().Time).ToCharArray()));
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Convert.ToString(obGen.ToString().ToCharArray())));
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Paths.Get("").ToAbsolutePath().Normalize().ToString().ToCharArray()));
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(hostName.ToCharArray()));
                byte[]     md5        = md.Digest();
                int        ssrc       = 0;
                ByteBuffer byteBuffer = ByteBuffer.Wrap(md5);
                for (int i = 0; i < 3; i++)
                {
                    ssrc ^= byteBuffer.Int;
                }
                return(ssrc);
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new RuntimeException("Could not get MD5 algorithm", e);
            }
        }