Beispiel #1
0
 public static string RemoveKeyType(string keyString)
 {
     if (String.IsNullOrEmpty(keyString))
     {
         return(keyString);
     }
     if (keyString.StartsWith(KeySchemeTable.GetKeySchemeValue(KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi)) ||
         keyString.StartsWith(KeySchemeTable.GetKeySchemeValue(KeySchemeTable.KeyScheme.DoubleLengthKeyVariant)) ||
         keyString.StartsWith(KeySchemeTable.GetKeySchemeValue(KeySchemeTable.KeyScheme.SingleDESKey)) ||
         keyString.StartsWith(KeySchemeTable.GetKeySchemeValue(KeySchemeTable.KeyScheme.TripleLengthKeyAnsi)) ||
         keyString.StartsWith(KeySchemeTable.GetKeySchemeValue(KeySchemeTable.KeyScheme.TripleLengthKeyVariant)))
     {
         return(keyString.Substring(1));
     }
     else
     {
         return(keyString);
     }
 }
Beispiel #2
0
        public static string EncryptUnderZMK(string clearZMK, string clearData, KeySchemeTable.KeyScheme ZMK_KeyScheme, string AtallaVariant)
        {
            string result = "";

            clearZMK = Utility.TransformUsingAtallaVariant(clearZMK, AtallaVariant);

            switch (ZMK_KeyScheme)
            {
            case KeySchemeTable.KeyScheme.SingleDESKey:
            case KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.TripleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.Unspecified:
                result = TripleDES.TripleDESEncrypt(new HexKey(clearZMK), clearData);
                break;

            case KeySchemeTable.KeyScheme.DoubleLengthKeyVariant:
            case KeySchemeTable.KeyScheme.TripleLengthKeyVariant:
                result = TripleDES.TripleDESEncryptVariant(new HexKey(clearZMK), clearData);
                break;

            default:
                break;
            }

            switch (ZMK_KeyScheme)
            {
            case KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.DoubleLengthKeyVariant:
            case KeySchemeTable.KeyScheme.TripleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.TripleLengthKeyVariant:
                result = KeySchemeTable.GetKeySchemeValue(ZMK_KeyScheme) + result;
                break;

            default:
                break;
            }

            return(result);
        }
Beispiel #3
0
        public static string DecryptUnderLMK(string encryptedKey, KeySchemeTable.KeyScheme Target_KeyScheme, LMKPairs.LMKPair LMKKeyPair, string variantNumber)
        {
            string result = "";

            switch (Target_KeyScheme)
            {
            case KeySchemeTable.KeyScheme.SingleDESKey:
            case KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.TripleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.Unspecified:
                result = TripleDES.TripleDESDecrypt(new HexKey(Cryptography.LMK.LMKStorage.LMKVariant(LMKKeyPair, Convert.ToInt32(variantNumber))), encryptedKey);
                break;

            case KeySchemeTable.KeyScheme.DoubleLengthKeyVariant:
            case KeySchemeTable.KeyScheme.TripleLengthKeyVariant:
                result = TripleDES.TripleDESDecryptVariant(new HexKey(Cryptography.LMK.LMKStorage.LMKVariant(LMKKeyPair, Convert.ToInt32(variantNumber))), encryptedKey);
                break;

            default:
                break;
            }


            switch (Target_KeyScheme)
            {
            case KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.DoubleLengthKeyVariant:
            case KeySchemeTable.KeyScheme.TripleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.TripleLengthKeyVariant:
                result = KeySchemeTable.GetKeySchemeValue(Target_KeyScheme) + result;
                break;

            default:
                break;
            }

            return(result);
        }
Beispiel #4
0
        public static string EncryptUnderLMK(string clearKey, KeySchemeTable.KeyScheme Target_KeyScheme, LMKPairs.LMKPair LMKKeyPair, string variantNumber)
        {
            string result = "";

            switch (Target_KeyScheme)
            {
            case KeySchemeTable.KeyScheme.SingleDESKey:
            case KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.TripleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.Unspecified:
                result = TripleDES.TripleDESEncrypt(new HexKey(Cryptography.LMK.LMKStorage.LMKVariant(LMKKeyPair, Convert.ToInt32(variantNumber))), clearKey);
                break;

            case KeySchemeTable.KeyScheme.DoubleLengthKeyVariant:
            case KeySchemeTable.KeyScheme.TripleLengthKeyVariant:
                result = TripleDES.TripleDESEncryptVariant(new HexKey(Cryptography.LMK.LMKStorage.LMKVariant(LMKKeyPair, Convert.ToInt32(variantNumber))), clearKey);
                break;

            default:
                //throw new InvalidOperationException("Invalid key scheme [" + Target_KeyScheme.ToString() + "]");
                break;
            }

            switch (Target_KeyScheme)
            {
            case KeySchemeTable.KeyScheme.DoubleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.DoubleLengthKeyVariant:
            case KeySchemeTable.KeyScheme.TripleLengthKeyAnsi:
            case KeySchemeTable.KeyScheme.TripleLengthKeyVariant:
                result = KeySchemeTable.GetKeySchemeValue(Target_KeyScheme) + result;
                break;

            default:
                break;
            }
            return(result);
        }