嗨@sriwin p有加密/解密文件測試用例代碼從公關https://github.com/sbt/sbt-pgp存儲庫。它提供了一個示例使用PGP加密/解密文件:
包com.jsuereth。pgp org.specs2.mutable進口。_進口sbt.io。IO進口IO。{BufferedWriter、文件,FileWriter}類KeyGenSpec擴展規範{PGP.init ()……val用戶= "測試用戶<(電子郵件保護)>“val pw:數組(Char) = " test-pw”。toCharArray瓦爾(酒吧,sec) = PGP。pw makeNewKeyRings(用戶)“加密和解密文件“{IO withTemporaryDirectory {dir = > val fileContent =一個字符串" val testFile1 =新文件(dir,“test1.txt”) val testFile2 =新文件(dir, test2.txt) / /原始文件val bw1 = new BufferedWriter(新FileWriter (testFile1)) bw1.write (fileContent) bw1.close () val source1 = scala.io.Source.fromFile (testFile1.getAbsolutePath) val lines1 = source1試試。mkString最後source1.close () / / System.out.println (lines1) - > / /加密解密文件準備val bw2 = new BufferedWriter(新FileWriter (testFile2)) bw2.write (fileContent) bw2.close () val testFileEncrypted =新文件sec.publicKey (dir,“testEncrypted.txt”)。encryptFile (testFile2 testFileEncrypted) testFile2.delete () sec.secretKey.decryptFile (testFileEncrypted, pw) val source2 = scala.io.Source.fromFile (testFile2.getAbsolutePath) val lines2 = source2試試。mkString最後source2.close () / / System.out.println lines2 lines1必須等於(lines2)}}……}
來源:https: / /github.com/CTiPKA/sbt-pgp/blob/develop/gpg-library/src/test/scala/com/jsuereth/pgp/KeyGenSpec.scala #吧
嗨@sriwin p有加密/解密文件測試用例代碼從公關https://github.com/sbt/sbt-pgp存儲庫。它提供了一個示例使用PGP加密/解密文件:
包com.jsuereth。pgp org.specs2.mutable進口。_進口sbt.io。IO進口IO。{BufferedWriter、文件,FileWriter}類KeyGenSpec擴展規範{PGP.init ()……val用戶= "測試用戶<(電子郵件保護)>“val pw:數組(Char) = " test-pw”。toCharArray瓦爾(酒吧,sec) = PGP。pw makeNewKeyRings(用戶)“加密和解密文件“{IO withTemporaryDirectory {dir = > val fileContent =一個字符串" val testFile1 =新文件(dir,“test1.txt”) val testFile2 =新文件(dir, test2.txt) / /原始文件val bw1 = new BufferedWriter(新FileWriter (testFile1)) bw1.write (fileContent) bw1.close () val source1 = scala.io.Source.fromFile (testFile1.getAbsolutePath) val lines1 = source1試試。mkString最後source1.close () / / System.out.println (lines1) - > / /加密解密文件準備val bw2 = new BufferedWriter(新FileWriter (testFile2)) bw2.write (fileContent) bw2.close () val testFileEncrypted =新文件sec.publicKey (dir,“testEncrypted.txt”)。encryptFile (testFile2 testFileEncrypted) testFile2.delete () sec.secretKey.decryptFile (testFileEncrypted, pw) val source2 = scala.io.Source.fromFile (testFile2.getAbsolutePath) val lines2 = source2試試。mkString最後source2.close () / / System.out.println lines2 lines1必須等於(lines2)}}……}
來源:https: / /github.com/CTiPKA/sbt-pgp/blob/develop/gpg-library/src/test/scala/com/jsuereth/pgp/KeyGenSpec.scala #吧