How to download the encrypted attachment in corda?

☆樱花仙子☆ 提交于 2019-12-13 06:17:35

问题


How to download the encrypted attachment in Corda? I have uploaded a file in corda and encrypted it and got the hash. How to download the same from other node?


回答1:


Consider, you have uploaded Jar as the attachment that contains a single file (e.g. legal agreement pdf), you can extract it as below:

//Get the attachmentJar from node for attachmentHash.
val attachmentJar: InputStream = cordaRPCOps.openAttachment(attachmentHash)

//Read the content of Jar to get file name and data.
var file_name_data: Pair<String, ByteArray>? = null
JarInputStream(attachment).use { jar ->
    while (true) {
        val nje = jar.nextEntry ?: break
        if (nje.isDirectory) {
            continue
        }
        file_name_data = Pair(nje.name, jar.readBytes())
    }
}



回答2:


If an attachment is referenced by hash in a transaction that node A sends to node B, and node B has never seen the attachment corresponding to that hash, they will automatically request the attachment from node A and cache it locally for future reference.




回答3:


 private fun downloadAttachment(proxy: CordaRPCOps, attachmentHash: SecureHash): JarInputStream {
        val attachmentDownloadInputStream = proxy.openAttachment(attachmentHash)
        return JarInputStream(attachmentDownloadInputStream)
    }


来源:https://stackoverflow.com/questions/50966758/how-to-download-the-encrypted-attachment-in-corda

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!