コード例 #1
0
        private string KeyOperation(bool decrypt, string key)
        {
            var scheme = KeyScheme.Unspecified;

            if (key.StartsWithKeyScheme())
            {
                scheme = key.GetKeyScheme();
            }

            string result;
            var    lmk = new HexKey(LMK.LmkStorage.LmkVariant(Code.Pair, Code.Variant));

            switch (scheme)
            {
            case KeyScheme.Unspecified:
            case KeyScheme.SingleLengthKey:
            case KeyScheme.DoubleLengthKeyAnsi:
            case KeyScheme.TripleLengthKeyAnsi:
                result = decrypt ? lmk.Decrypt(key.StripKeyScheme()) : lmk.Encrypt(key.StripKeyScheme());
                break;

            default:
                result = decrypt
                                 ? lmk.DecryptVariant(key.StripKeyScheme())
                                 : lmk.EncryptVariant(key.StripKeyScheme());
                break;
            }

            return(scheme != KeyScheme.Unspecified && scheme != KeyScheme.SingleLengthKey
                          ? scheme.GetKeySchemeChar() + result
                          : result);
        }
コード例 #2
0
        private void CalculateEncryptedValues()
        {
            var scheme = KeyScheme.Unspecified;

            if (Key.StartsWithKeyScheme())
            {
                scheme = Key.GetKeyScheme();
            }
            else if (scheme == KeyScheme.Unspecified && Key.GetKeyLength() != KeyLength.SingleLength)
            {
                switch (Key.GetKeyLength())
                {
                case KeyLength.DoubleLength:
                    scheme = KeyScheme.DoubleLengthKeyAnsi;
                    break;

                default:
                    scheme = KeyScheme.TripleLengthKeyAnsi;
                    break;
                }

                Key = scheme.GetKeySchemeChar() + Key;
            }

            var lmk = new HexKey(LMK.LmkStorage.LmkVariant(Code.Pair, Code.Variant));

            switch (scheme)
            {
            case KeyScheme.Unspecified:
            case KeyScheme.SingleLengthKey:
                KeyVariant = string.Empty;
                KeyAnsi    = Key;
                break;

            case KeyScheme.DoubleLengthKeyAnsi:
            case KeyScheme.TripleLengthKeyAnsi:
                KeyAnsi    = Key;
                KeyVariant = lmk.EncryptVariant(ClearKey);
                switch (scheme)
                {
                case KeyScheme.DoubleLengthKeyAnsi:
                    KeyVariant = KeyScheme.DoubleLengthKeyVariant.GetKeySchemeChar() + KeyVariant;
                    break;

                case KeyScheme.TripleLengthKeyAnsi:
                    KeyVariant = KeyScheme.TripleLengthKeyVariant.GetKeySchemeChar() + KeyVariant;
                    break;
                }
                break;

            default:
                KeyVariant = Key;
                KeyAnsi    = lmk.Encrypt(ClearKey);
                switch (scheme)
                {
                case KeyScheme.DoubleLengthKeyVariant:
                    KeyAnsi = KeyScheme.DoubleLengthKeyAnsi.GetKeySchemeChar() + ClearKey;
                    break;

                case KeyScheme.TripleLengthKeyVariant:
                    KeyAnsi = KeyScheme.TripleLengthKeyVariant.GetKeySchemeChar() + ClearKey;
                    break;
                }
                break;
            }
        }