kandi background
Explore Kits

JNCryptor | Java implementation of RNCryptor | Encryption library

 by   RNCryptor Java Version: jncryptor-1.2.0 License: Apache-2.0

 by   RNCryptor Java Version: jncryptor-1.2.0 License: Apache-2.0

Download this library from

kandi X-RAY | JNCryptor Summary

JNCryptor is a Java library typically used in Security, Encryption applications. JNCryptor has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can download it from GitHub, Maven.
The Javadocs can be browsed online: [JNCryptor Javadocs](http://rncryptor.github.io/JNCryptor/javadoc/).
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • JNCryptor has a low active ecosystem.
  • It has 187 star(s) with 50 fork(s). There are 16 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 3 open issues and 45 have been closed. On average issues are closed in 303 days. There are 1 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of JNCryptor is jncryptor-1.2.0
JNCryptor Support
Best in #Encryption
Average in #Encryption
JNCryptor Support
Best in #Encryption
Average in #Encryption

quality kandi Quality

  • JNCryptor has 0 bugs and 0 code smells.
JNCryptor Quality
Best in #Encryption
Average in #Encryption
JNCryptor Quality
Best in #Encryption
Average in #Encryption

securitySecurity

  • JNCryptor has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • JNCryptor code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
JNCryptor Security
Best in #Encryption
Average in #Encryption
JNCryptor Security
Best in #Encryption
Average in #Encryption

license License

  • JNCryptor is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
JNCryptor License
Best in #Encryption
Average in #Encryption
JNCryptor License
Best in #Encryption
Average in #Encryption

buildReuse

  • JNCryptor releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 2501 lines of code, 226 functions and 32 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
JNCryptor Reuse
Best in #Encryption
Average in #Encryption
JNCryptor Reuse
Best in #Encryption
Average in #Encryption
Top functions reviewed by kandi - BETA

kandi has reviewed JNCryptor and discovered the below as its top functions. This is intended to give you an instant insight into JNCryptor implemented functionality, and help decide if they suit your requirements.

  • Initializes the stream .
  • Encodes the ciphertext .
  • Returns true if this instance equals another ciphertext .
  • Decrypts the given ciphertext using the given HMAC encryption key .
  • Encrypts a plaintext using the given encryption key .
  • Creates MAC streams and HMAC streams .
  • Read bytes into a byte array .
  • Fills the trailer buffer .
  • Writes the header .
  • Read all bytes from the input stream .

JNCryptor Key Features

Java implementation of RNCryptor

Getting JNCryptor

copy iconCopydownload iconDownload
<dependency>
    <groupId>org.cryptonode.jncryptor</groupId>
    <artifactId>jncryptor</artifactId>
    <version>1.2.0</version>
</dependency>
````

Using JNCryptor
----------------

A quick example is shown below:

```java
JNCryptor cryptor = new AES256JNCryptor();
byte[] plaintext = "Hello, World!".getBytes();
String password = "secretsquirrel";

try {
  byte[] ciphertext = cryptor.encryptData(plaintext, password.toCharArray());
} catch (CryptorException e) {
  // Something went wrong
  e.printStackTrace();
}

JNCryptor - RNCryptor Image file encryption / decryption

copy iconCopydownload iconDownload
//Encrypt file
/**
 *
var encryptedData = RNCryptor.encrypt(data: data as Data, withPassword: hashKey.description)
try encryptedData.write(to: fileURL)
 fileBytes - 3,1,-54,106
 encrypted - 3,1,71,68
 * */
fun encryptFile( inputFile : File, privateKey : CharArray ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Encrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val encryptedFileBytes = aeS256JNCryptor.encryptData(fileBytes, privateKey)

        val bufOut = BufferedOutputStream(FileOutputStream(file))
        bufOut.write(encryptedFileBytes)

        buf.close()
        bufOut.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file

}

//Decrypt file
/**
 *
let encryptedData = fileManager.contents(atPath: filePathNormal)
let decryptedData = try RNCryptor.decrypt(data: encryptedData!, withPassword: hashKey.description)
let selected_image = UIImage.sd_image(with: decryptedData)
encrypted - 3,1,71,68
decrypted Bytes - 3,1,-54,106
 * */
fun decryptFile( inputFile : File, privateKey: CharArray ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Decrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val decryptedFileBytes = aeS256JNCryptor.decryptData(fileBytes, privateKey)

        if( file.exists() ) file.delete()

        val fileOutputStream = FileOutputStream( file.absolutePath )
        fileOutputStream.write(decryptedFileBytes)

        buf.close()
        fileOutputStream.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file
}

Failed to resolve Gradle dependency

copy iconCopydownload iconDownload
sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: 
unable to find valid certification path to requested target

Community Discussions

Trending Discussions on JNCryptor
  • JNCryptor - RNCryptor Image file encryption / decryption
  • Failed to resolve Gradle dependency
Trending Discussions on JNCryptor

QUESTION

JNCryptor - RNCryptor Image file encryption / decryption

Asked 2018-Feb-05 at 07:04

I am trying to get image encryption / decryption working using AES256 implementation of RNCryptor Library.

This is my code so far :

//Encrypt file
/**
 *
var encryptedData = RNCryptor.encrypt(data: data as Data, withPassword: hashKey.description)
try encryptedData.write(to: fileURL)
 * */
fun encryptFile( inputFile : File ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Encrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val encryptedFileBytes = aeS256JNCryptor.encryptData(fileBytes, "master".toCharArray())

        val bufOut = BufferedOutputStream(FileOutputStream(file))
        bufOut.write(encryptedFileBytes)

        buf.close()
        bufOut.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file

}

//Decrypt file
/**
 *
let encryptedData = fileManager.contents(atPath: filePathNormal)
let decryptedData = try RNCryptor.decrypt(data: encryptedData!, withPassword: hashKey.description)
let selected_image = UIImage.sd_image(with: decryptedData)
 * */
fun decryptFile( inputFile : File ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Decrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val decryptedFileBytes = aeS256JNCryptor.decryptData(fileBytes, "master".toCharArray())

        val bufOut = BufferedOutputStream(file.outputStream())
        bufOut.write(decryptedFileBytes)

        buf.close()
        bufOut.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file
}

Post decryption I am unable to load / view the image. I have posted relevant iOS code used in the comments. Please let me know if I am going wrong somewhere.

Here are somethings I've already tried with no success :

fun decryptFile( inputFile : File ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Decrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val decryptedFileBytes = aeS256JNCryptor.decryptData(fileBytes, "master".toCharArray())

        if( file.exists() ) file.delete()

        //val bufOut = BufferedOutputStream(file.outputStream())
        //bufOut.write(decryptedFileBytes)

        val fileOutputStream = FileOutputStream( file.absolutePath )
        fileOutputStream.write(decryptedFileBytes)
        buf.close()
        fileOutputStream.close()
        //bufOut.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file
}

Alternate way to save bitmap :

val fileOutputStream = FileOutputStream( file.absolutePath )
        //fileOutputStream.write(decryptedFileBytes)

val bitmap = BitmapFactory.decodeByteArray(decryptedFileBytes, 0, decryptedFileBytes.size)
if( bitmap != null )
   bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)


buf.close()
fileOutputStream.close()

I am able to see the decrypted file, the size matches with that of original file, tried debugging byte array conversion to ensure bytes are the same as the original.

I am unable to open file either in Gallery / in app when loading it in an imageview.

ANSWER

Answered 2018-Feb-05 at 07:04

It was solved by changing the way password is encrypted and used.

Here's what worked :

//Encrypt file
/**
 *
var encryptedData = RNCryptor.encrypt(data: data as Data, withPassword: hashKey.description)
try encryptedData.write(to: fileURL)
 fileBytes - 3,1,-54,106
 encrypted - 3,1,71,68
 * */
fun encryptFile( inputFile : File, privateKey : CharArray ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Encrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val encryptedFileBytes = aeS256JNCryptor.encryptData(fileBytes, privateKey)

        val bufOut = BufferedOutputStream(FileOutputStream(file))
        bufOut.write(encryptedFileBytes)

        buf.close()
        bufOut.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file

}

//Decrypt file
/**
 *
let encryptedData = fileManager.contents(atPath: filePathNormal)
let decryptedData = try RNCryptor.decrypt(data: encryptedData!, withPassword: hashKey.description)
let selected_image = UIImage.sd_image(with: decryptedData)
encrypted - 3,1,71,68
decrypted Bytes - 3,1,-54,106
 * */
fun decryptFile( inputFile : File, privateKey: CharArray ) : File {

    val size = inputFile.length().toInt()
    val fileBytes = ByteArray(size)
    val aeS256JNCryptor = AES256JNCryptor()
    val file = File(Environment.getExternalStorageDirectory().toString() + "/Decrypted_" + inputFile.name)
    try {
        val buf = BufferedInputStream(FileInputStream(inputFile))
        buf.read(fileBytes, 0, fileBytes.size)

        val decryptedFileBytes = aeS256JNCryptor.decryptData(fileBytes, privateKey)

        if( file.exists() ) file.delete()

        val fileOutputStream = FileOutputStream( file.absolutePath )
        fileOutputStream.write(decryptedFileBytes)

        buf.close()
        fileOutputStream.close()

    } catch (e: FileNotFoundException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    } catch (e: IOException) {
        // TODO Auto-generated catch block
        e.printStackTrace()
    }

    return file
}

privateKey is a random alphanumeric string of length 16. Once generated, it needs to be reused while encrypting and decrypting file.

Source https://stackoverflow.com/questions/48419188

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install JNCryptor

You can download it from GitHub, Maven.
You can use JNCryptor like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the JNCryptor component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Compare Encryption Libraries with Highest Support
Compare Encryption Libraries with Permissive License
Compare Encryption Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.