EasyCrypt


Source link: https://github.com/ryan652/easycrypt

EasyCrypt

Secure and efficient cryptography library for Android. (Auto fix SecureRandom bugs in API 18 and below.)

Features

  • AES-256 encryption algorithm
  • CBC/CTR mode of operations
  • Block padding with PKCS7 (only with CBC)
  • Computationally secure random salt (of cipher block size)
  • Password stretching with PBKDF2
  • Random IV generated on each encryption (16 bytes)
  • Supports MD5, SHA1, and SHA2 hash functions
  • Generate secure keys with SecureRandom or random.org
  • Asymmetric encryption with RSA
  • Auto handle large data by using hybrid asymmetric encryption
  • Asymmetric RSA signing and verification
  • Supported RSA key sizes are 2048 bits and 4096 bits
  • Password analysis for strength, crack times, weakness, etc using nulab's zxcvbn4j library

Install in Java app

Add in your project's build.gradle

buildscript {

  ..
  dependencies {

..

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2"

classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.1.3-2"
  
}

  .. 
}

Add in your app's build.gradle

apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions'  dependencies {

  ..
  compile "com.pvryan.easycrypt:easycrypt:1.3.0"
  compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3"
  compile "org.jetbrains.anko:anko-commons:0.10.1"
  .. 
}

Install in Kotlin app

Add in your app's build.gradle

dependencies {

  ..
  compile "com.pvryan.easycrypt:easycrypt:1.3.0"
  .. 
}

Usage

val eCryptSymmetric = ECSymmetric() val eCryptAsymmetric = ECAsymmetric() val eCryptHash = ECHash() val eCryptPass = ECPasswords()

Symmetric key encryption

Encrypt data

eCryptSymmetric.encrypt (input, password,
  object : ECResultListener {

 // Optional

override fun onProgress(newBytes: Int, bytesProcessed: Long) {

 
}

 override fun <T> onSuccess(result: T) {

 
}

 override fun onFailure(message: String, e: Exception) {

 
}

  
}
,
  outputFile // Optional )

Decrypt data

eCryptSymmetric.decrypt(input, password,

object : ECResultListener {

  // Optional

 override fun onProgress(newBytes: Int, bytesProcessed: Long) {

  
}

  override fun <T> onSuccess(result: T) {

  
}

  override fun onFailure(message: String, e: Exception) {

  
}

}
,

outputFile // Optional )

Asymmetric key encryption

Encrypt data

eCryptAsymmetric.generateKeyPair(object : ECRSAKeyPairListener {

 override fun onSuccess(keyPair: KeyPair) {

 privateKey = keyPair.private as RSAPrivateKey // Save private key

 eCryptAsymmetric.encrypt(input, keyPair.public as RSAPublicKey,

object : ECResultListener {

  // Optional

 override fun onProgress(newBytes: Int, bytesProcessed: Long) {

  
}

  override fun <T> onSuccess(result: T) {

  
}

  override fun onFailure(message: String, e: Exception) {

  
}

}
,

outputFile // Optional

 )

}

 override fun onFailure(message: String, e: Exception) {

 e.printStackTrace()

}

}
, keySize = eCryptAsymmetric.KeySizes._4096)

Decrypt data

eCryptAsymmetric.decrypt(input, privateKey,

object : ECResultListener {

  // Optional

 override fun onProgress(newBytes: Int, bytesProcessed: Long) {

  
}

  override fun <T> onSuccess(result: T) {

  
}

  override fun onFailure(message: String, e: Exception) {

  
}

}
,

outputFile // Optional )

Sign data

eCryptKeys.genRSAKeyPair(object : ECRSAKeyPairListener {

override fun onGenerated(keyPair: KeyPair) {

 publicKey = keyPair.public as RSAPublicKey

 eCryptAsymmetric.sign(input,

  keyPair.private as RSAPrivateKey,

  object : ECResultListener {

 // Optional

override fun onProgress(newBytes: Int, bytesProcessed: Long) {

 
}

 override fun <T> onSuccess(result: T) {

 
}

 override fun onFailure(message: String, e: Exception) {

 
}

  
}
,

  signatureOutputFile)
  
}

override fun onFailure(message: String, e: Exception) {

}
 
}
)

Verify data

eCryptAsymmetric.verify(input, publicKey, signatureFile,

object : ECVerifiedListener {

 override fun onSuccess(verified: Boolean) {

  
}

  override fun onFailure(message: String, e: Exception) {

  
}

}
 )

Hash data

eCryptHash.calculate(input, hashAlgorithm, // from ECHashAlgorithms

object : ECResultListener {

  // Optional

 override fun onProgress(newBytes: Int, bytesProcessed: Long) {

  
}

  override fun <T> onSuccess(result: T) {

  
}

  override fun onFailure(message: String, e: Exception) {

  
}

}
,

outputFile // Optional )

Analyze password

val analysis: ECPasswordAnalysis = ECPasswordAnalyzer.analyze("thisismypassword")

Input Output
File outputFile
FileInputStream outputFile
ByteArray String or outputFile (if provided)
ByteArrayInputStream String or outputFile (if provided)
String String or outputFile (if provided)
CharSequence String or outputFile (if provided)
Anything else InvalidParameterException

Generate key with SecureRandom (pseudo-random)

val password = eCryptPass.genSecureRandomPassword(length, charArrayOf(/*symbols to be used in password*/))

Generate key with Random.org (true random)

For sample to work enter your API key in FragmentPasswords

eCryptPass.genRandomOrgPassword(

length,

"random-org-api-key", //TODO: Replace with your random.org api key

new ECPasswordListener() {

  @Override

 public void onFailure(@NonNull String message, @NonNull Exception e) {

  
}

  @Override

 public void onSuccess(@NonNull String password) {

  
}

}
);

License

Copyright 2017 Priyank Vasa Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

android-Ultra-Pull-To-Refresh is a replacement for the deprecated pull-to-refresh-solution. It can contain any view that you want.

Client of iComet server for Java/Android iComet server This project is based the iComet service

Simply, this project is an implements of client for iComet service. You can use it in your java project as well as Android project.

When you apply the plugin and install an app all debug version icons will have flavor, build type and version name.

This library is design to insert cursor row inside another cursor or insert dummy row inside actual cursor.

MathFu is a C++ math library developed primarily for games focused on simplicity and efficiency.

It provides a suite of vector, matrix and quaternion classes to perform basic geometry suitable for game developers. This functionality can be used to construct geometry for graphics libraries like OpenGL or perform calculations for animation or physics systems.

Simple and smooth PDF viewer for Android applications. This project use copy of MuPDF as library module.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes