Exemple #1
0
        private static byte[] ConvertToBinaryIdentifier(string keyIdentifier, KeyCredentialVersion version)
        {
            switch (version)
            {
            case KeyCredentialVersion.Version0:
            case KeyCredentialVersion.Version1:
                return(keyIdentifier.HexToBinary());

            case KeyCredentialVersion.Version2:
            default:
                return(Convert.FromBase64String(keyIdentifier));
            }
        }
Exemple #2
0
        private static string ConvertFromBinaryIdentifier(byte[] binaryId, KeyCredentialVersion version)
        {
            switch (version)
            {
            case KeyCredentialVersion.Version0:
            case KeyCredentialVersion.Version1:
                return(binaryId.ToHex(true));

            case KeyCredentialVersion.Version2:
            default:
                return(Convert.ToBase64String(binaryId));
            }
        }
Exemple #3
0
        private static byte[] ConvertToBinaryTime(DateTime time, KeySource source, KeyCredentialVersion version)
        {
            long timeStamp;

            switch (version)
            {
            case KeyCredentialVersion.Version0:
                timeStamp = time.Ticks;
                break;

            case KeyCredentialVersion.Version1:
                timeStamp = time.ToBinary();
                break;

            case KeyCredentialVersion.Version2:
            default:
                timeStamp = source == KeySource.AD ? time.ToFileTime() : time.ToBinary();
                break;
            }

            return(BitConverter.GetBytes(timeStamp));
        }
Exemple #4
0
 private static string ComputeKeyIdentifier(byte[] keyMaterial, KeyCredentialVersion version)
 {
     byte[] binaryId = ComputeHash(keyMaterial);
     return(ConvertFromBinaryIdentifier(binaryId, version));
 }
Exemple #5
0
        private static DateTime ConvertFromBinaryTime(byte[] binaryTime, KeySource source, KeyCredentialVersion version)
        {
            long timeStamp = BitConverter.ToInt64(binaryTime, 0);

            // AD and AAD use a different time encoding.
            switch (version)
            {
            case KeyCredentialVersion.Version0:
                return(new DateTime(timeStamp));

            case KeyCredentialVersion.Version1:
                return(DateTime.FromBinary(timeStamp));

            case KeyCredentialVersion.Version2:
            default:
                return(source == KeySource.AD ? DateTime.FromFileTime(timeStamp) : DateTime.FromBinary(timeStamp));
            }
        }