keepass2android/src/ArtTestApp/Activity1.cs

99 lines
2.8 KiB
C#
Raw Normal View History

using System;
2014-06-19 10:13:16 -04:00
using System.Collections.Generic;
2014-07-30 00:25:37 -04:00
using System.Diagnostics;
using System.Security.Cryptography;
using Android.App;
using Android.Content;
2014-06-19 10:13:16 -04:00
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
2014-07-30 00:25:37 -04:00
//using KeePassLib.Serialization;
using MasterPassword;
//using keepass2android;
//using keepass2android.Io;
namespace ArtTestApp
{
[Activity(Label = "ArtTestApp", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
2014-07-30 00:25:37 -04:00
//private IOConnectionInfo _ioConnectionInfo;
//private IOConnectionInfo _ioConnectionInfoOut;
2014-06-19 10:13:16 -04:00
private const int RequestCodeChallengeYubikey = 98;
2014-07-30 00:25:37 -04:00
private static byte[] HashHMAC(byte[] key, byte[] message)
{
var hash = new HMACSHA256(key);
return hash.ComputeHash(message);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
2014-07-30 00:25:37 -04:00
/*_ioConnectionInfo = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallenge.xml" };
2014-06-19 10:13:16 -04:00
_ioConnectionInfoOut = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallengeOut.xml" };
2014-07-30 00:25:37 -04:00
*/
FindViewById<Button>(Resource.Id.MyButton1).Text = "";
Stopwatch sw = new Stopwatch();
sw.Start();
var key = new MpAlgorithm().GetKeyForPassword("u", "test");
sw.Stop();
string password = MpAlgorithm.GenerateContent("Long Password", "strn", key, 1, HashHMAC);
FindViewById<Button>(Resource.Id.MyButton1).Text = password;
FindViewById<Button>(Resource.Id.MyButton2).Text = sw.ElapsedMilliseconds.ToString();
2014-06-19 10:13:16 -04:00
// Get our button from the layout resource,
// and attach an event to it
FindViewById<Button>(Resource.Id.MyButton1).Click += (sender, args) =>
{
2014-07-30 00:25:37 -04:00
// Decrypt(_ioConnectionInfo);
2014-06-19 10:13:16 -04:00
};
2014-05-21 00:48:49 -04:00
FindViewById<Button>(Resource.Id.MyButton2).Click += (sender, args) =>
{
2014-07-30 00:25:37 -04:00
//Decrypt(_ioConnectionInfoOut);
2014-05-21 00:48:49 -04:00
};
FindViewById<Button>(Resource.Id.MyButton3).Click += (sender, args) => StartActivityForResult(typeof(PrefActivity), 1);
2014-05-21 00:48:49 -04:00
}
2014-06-19 10:13:16 -04:00
2014-07-30 00:25:37 -04:00
/*private void Decrypt(IOConnectionInfo ioConnectionInfo)
2014-06-19 10:13:16 -04:00
{
try
{
//StartActivity(typeof (Activity2));
_chalInfo = ChallengeInfo.Load(ioConnectionInfo);
Intent chalIntent = new Intent("com.yubichallenge.NFCActivity.CHALLENGE");
chalIntent.PutExtra("challenge", _chalInfo.Challenge);
chalIntent.PutExtra("slot", 2);
chalIntent.AddFlags(ActivityFlags.SingleTop);
IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
StartActivityForResult(chalIntent, RequestCodeChallengeYubikey);
}
}
catch (Exception ex)
{
Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
}
2014-07-30 00:25:37 -04:00
}*/
2014-06-19 10:13:16 -04:00
}
}