Skip to content
This repository was archived by the owner on Aug 29, 2020. It is now read-only.

Commit 6fd061a

Browse files
committed
Upload Project
1 parent 7df525b commit 6fd061a

File tree

19 files changed

+343
-32
lines changed

19 files changed

+343
-32
lines changed

.gitignore

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1 @@
1-
# Built application files
2-
*.apk
3-
*.ap_
4-
5-
# Files for the Dalvik VM
6-
*.dex
7-
8-
# Java class files
9-
*.class
10-
11-
# Generated files
12-
bin/
13-
gen/
14-
15-
# Gradle files
16-
.gradle/
17-
build/
18-
19-
# Local configuration file (sdk path, etc)
20-
local.properties
21-
22-
# Proguard folder generated by Eclipse
23-
proguard/
24-
25-
# Log Files
26-
*.log
27-
28-
# Android Studio Navigation editor temp files
29-
.navigation/
30-
31-
# Android Studio captures folder
32-
captures/
1+
/build

app/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.koswu.kpassword"
9+
minSdkVersion 14
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "0.1.0_alpha"
13+
}
14+
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
compile 'com.android.support:appcompat-v7:+'
25+
compile fileTree(dir: 'libs', include: ['*.jar'])
26+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\tools\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.koswu.kpassword">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme">
10+
11+
<activity
12+
android:name=".MainActivity"
13+
android:label="@string/app_name">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
</intent-filter>
18+
</activity>
19+
20+
</application>
21+
22+
</manifest>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.koswu.kpassword;
2+
3+
import android.content.ClipboardManager;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.text.TextUtils;
8+
import android.view.View;
9+
import android.view.View.OnClickListener;
10+
import android.widget.Button;
11+
import android.widget.EditText;
12+
import android.widget.TextView;
13+
import android.widget.Toast;
14+
import com.koswu.kpassword.MainActivity;
15+
import com.koswu.kpassword.tool.PassWord;
16+
17+
public class MainActivity extends AppCompatActivity
18+
{
19+
private Button button_create=null;
20+
private Button button_copy=null;
21+
private EditText edittext_memory_password=null;
22+
private EditText edittext_diff_code=null;
23+
TextView textview_created_password=null;
24+
String created_password="";
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState)
27+
{
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.main);
30+
button_create=(Button)findViewById(R.id.button_create);
31+
button_copy=(Button)findViewById(R.id.button_copy);
32+
edittext_memory_password=(EditText)findViewById(R.id.edittext_input_password);
33+
edittext_diff_code=(EditText)findViewById(R.id.edittext_input_code);
34+
textview_created_password=(TextView)findViewById(R.id.textview_password);
35+
button_create.setOnClickListener(new OnClickListener()
36+
{
37+
38+
@Override
39+
public void onClick(View p1)
40+
{
41+
// TODO: Implement this method
42+
String diff_code=edittext_diff_code.getText().toString();
43+
String memory_password=edittext_memory_password.getText().toString();
44+
if(!(
45+
TextUtils.isEmpty(diff_code)||
46+
TextUtils.isEmpty(memory_password)
47+
))
48+
{
49+
try
50+
{
51+
created_password=PassWord.CreatePassword(memory_password,diff_code);
52+
}
53+
catch (Exception e)
54+
{
55+
e.printStackTrace();
56+
}
57+
textview_created_password.setText(created_password);
58+
}
59+
else
60+
{
61+
textview_created_password.setText("Unknown");
62+
}
63+
}
64+
65+
66+
});
67+
button_copy.setOnClickListener(new OnClickListener()
68+
{
69+
70+
@Override
71+
public void onClick(View p1)
72+
{
73+
// TODO: Implement this method
74+
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
75+
clipboard.setText(created_password.trim());
76+
Toast.makeText(MainActivity.this,"已复制,酷爱拿去用吧",Toast.LENGTH_SHORT).show();
77+
}
78+
79+
80+
});
81+
}
82+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.koswu.kpassword.tool;
2+
import java.io.UnsupportedEncodingException;
3+
import java.security.InvalidKeyException;
4+
import java.security.NoSuchAlgorithmException;
5+
import java.security.spec.InvalidKeySpecException;
6+
import javax.crypto.Mac;
7+
import javax.crypto.SecretKey;
8+
import javax.crypto.SecretKeyFactory;
9+
import javax.crypto.spec.PBEKeySpec;
10+
import javax.crypto.spec.SecretKeySpec;
11+
import android.util.Base64;
12+
13+
public class PassWord
14+
{
15+
private static final String UTF_8="UTF-8";
16+
private static final String HMAC_SHA256="HmacSHA256";
17+
//private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd','e', 'f' };
18+
//private static final String PASSWORD_DIC="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
19+
public static String CreatePassword(String memory_password,String diff_code) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException
20+
{
21+
22+
String transformd_string= EncodeHmacSHA256(memory_password,diff_code);
23+
String len16_string;
24+
int transformd_string_lenth=transformd_string.length();
25+
char head_char=transformd_string.charAt(0);
26+
if (head_char=='_'||
27+
head_char=='-'||
28+
Character.isDigit(head_char))
29+
{
30+
len16_string=transformd_string.substring(transformd_string_lenth-17,transformd_string_lenth-1);
31+
head_char=len16_string.charAt(0);
32+
if (head_char=='_'||
33+
head_char=='-'||
34+
Character.isDigit(head_char))
35+
{
36+
len16_string="K"+len16_string.substring(1,16);
37+
}
38+
}
39+
else
40+
{
41+
len16_string=transformd_string.substring(0,16);
42+
}
43+
return len16_string;
44+
}
45+
private static String EncodeHmacSHA256 (String password_string,String key_string) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException
46+
{
47+
byte password_bytes[]=password_string.getBytes(UTF_8);
48+
byte code_bytes[]=key_string.getBytes(UTF_8);
49+
SecretKey secret_key=new SecretKeySpec(code_bytes,HMAC_SHA256);
50+
String result_string;
51+
Mac mac=Mac.getInstance(secret_key.getAlgorithm());
52+
mac.init(secret_key);
53+
byte result_bytes[]=mac.doFinal(password_bytes);
54+
result_string=ByteToBASE64(result_bytes);
55+
/*if (result_string.charAt(0)=='-')
56+
{
57+
result_string.replace('-','K');
58+
}
59+
if (result_string.charAt(0)=='_')
60+
{
61+
result_string.replace('_','K');
62+
}*/
63+
return result_string;
64+
}
65+
private static String ByteToBASE64(byte []datas)
66+
{
67+
return Base64.encodeToString(datas,Base64.URL_SAFE|Base64.NO_PADDING|Base64.NO_WRAP);
68+
}
69+
70+
private static byte[] pbkdf2(char[] key, int iterations, int bytes)
71+
throws NoSuchAlgorithmException, InvalidKeySpecException
72+
{
73+
byte salt[] = {2,3,3,3,3,3,3,3};
74+
PBEKeySpec spec = new PBEKeySpec(key, salt, iterations, bytes * 8);
75+
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
76+
return skf.generateSecret(spec).getEncoded();
77+
}
78+
}

app/src/main/res/layout/main.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<TextView
8+
android:layout_height="wrap_content"
9+
android:layout_width="match_parent"
10+
android:text="@string/memory_password"/>
11+
<EditText
12+
android:id="@+id/edittext_input_password"
13+
android:layout_height="wrap_content"
14+
android:layout_width="match_parent"
15+
android:hint="@string/input_your_password"
16+
android:inputType="textPassword"/>
17+
<TextView
18+
android:layout_height="wrap_content"
19+
android:layout_width="match_parent"
20+
android:text="@string/diff_code"/>
21+
<EditText
22+
android:id="@+id/edittext_input_code"
23+
android:layout_height="wrap_content"
24+
android:layout_width="match_parent"
25+
android:hint="@string/input_your_code"/>
26+
<Button
27+
android:id="@+id/button_create"
28+
android:layout_height="wrap_content"
29+
android:layout_width="match_parent"
30+
android:text="@string/create"/>
31+
<TextView
32+
android:layout_height="wrap_content"
33+
android:layout_width="match_parent"
34+
android:text="@string/password_create_area"/>
35+
<TextView
36+
android:id="@+id/textview_password"
37+
android:layout_height="wrap_content"
38+
android:layout_width="wrap_content"
39+
android:textSize="30dip"
40+
android:text="Unknown"/>
41+
<Button
42+
android:id="@+id/button_copy"
43+
android:layout_height="wrap_content"
44+
android:layout_width="match_parent"
45+
android:text="@string/copy"/>
46+
<TextView
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:text="内部测试版本"/>
50+
51+
52+
</LinearLayout>
1.29 KB
Loading
862 Bytes
Loading
1.69 KB
Loading

0 commit comments

Comments
 (0)