Пример #1
0
        KeyMaterial64 CreateKeyMaterialFromPassphrase(string passphrase)
        {
            NormalizedPassword normalizedPassword = this.xdsCryptoService.NormalizePassword(passphrase).Result;
            KeyMaterial64      hashedPassword     = this.xdsCryptoService.HashPassword(normalizedPassword).Result;

            return(hashedPassword);
        }
Пример #2
0
        public static byte[] EncryptWithPassphrase(string passphrase, byte[] bytesToEncryt)
        {
            var context = GetContext();
            NormalizedPassword normalizedPassword           = Instance().NormalizePassword(passphrase).Result;
            KeyMaterial64      passwordDerivedkeyMaterial64 = Instance().HashPassword(normalizedPassword).Result;
            CipherV2           cipherV2 = Instance().BinaryEncrypt(new Clearbytes(bytesToEncryt), passwordDerivedkeyMaterial64, new RoundsExponent(RoundsExponent.DontMakeRounds), context).Result;
            var cipherV2Bytes           = Instance().BinaryEncodeXDSSec(cipherV2, context).Result;

            return(cipherV2Bytes);
        }
Пример #3
0
        public static NormalizedPassword NormalizePassword(PasswordObject password)
        {
            var normalizedPassword = new NormalizedPassword
            {
                Id         = password.Id,
                Encryption = String.IsNullOrEmpty(password.Secret) ? password.Encryption : password.Secret,
                Integrity  = String.IsNullOrEmpty(password.Secret) ? password.Integrity : password.Secret
            };

            return(normalizedPassword);
        }
Пример #4
0
        public static byte[] DecryptWithPassphrase(string passphrase, byte[] bytesToDecrypt)
        {
            var context = GetContext();
            NormalizedPassword normalizedPassword           = Instance().NormalizePassword(passphrase).Result;
            KeyMaterial64      passwordDerivedkeyMaterial64 = Instance().HashPassword(normalizedPassword).Result;
            CipherV2           cipherV2 = Instance().BinaryDecodeXDSSec(bytesToDecrypt, context).Result;
            var response = Instance().BinaryDecrypt(cipherV2, passwordDerivedkeyMaterial64, context);

            if (response.IsSuccess)
            {
                return(response.Result.GetBytes());
            }
            return(null);
        }
Пример #5
0
        public Response <KeyMaterial64> HashPassword(NormalizedPassword normalizedPassword)
        {
            var response = new Response <KeyMaterial64>();

            try
            {
                Guard.NotNull(normalizedPassword);
                EnsurePlatform();

                var utf16LeBytes = Encoding.Unicode.GetBytes(normalizedPassword.Text);

                var sha512 = this._platform.ComputeSHA512(utf16LeBytes);

                response.Result = new KeyMaterial64(sha512);
                response.SetSuccess();
            }
            catch (Exception e)
            {
                response.SetError(e);
            }
            return(response);
        }