mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-04-04 05:17:36 +03:00
fix: Base64 encoder as external library
This commit is contained in:
parent
13f2003fed
commit
1b96747187
5 changed files with 33 additions and 42 deletions
|
@ -20,10 +20,8 @@ package com.kunzisoft.keepass.database.element
|
|||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import com.kunzisoft.encrypt.HashManager
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import com.kunzisoft.keepass.utils.StringUtil.removeSpaceChars
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toHexString
|
||||
|
@ -31,6 +29,7 @@ import com.kunzisoft.keepass.utils.readByteArrayCompat
|
|||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeByteArrayCompat
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.apache.commons.codec.binary.Hex
|
||||
import org.w3c.dom.Node
|
||||
import java.io.ByteArrayInputStream
|
||||
|
@ -212,9 +211,7 @@ data class MasterCredential(var password: String? = null,
|
|||
when (xmlKeyFileVersion) {
|
||||
1F -> {
|
||||
// No hash in KeyFile XML version 1
|
||||
return Base64.decode(dataString,
|
||||
DatabaseKDBX.BASE_64_FLAG
|
||||
)
|
||||
return Base64.decodeBase64(dataString)
|
||||
}
|
||||
2F -> {
|
||||
return if (hashString != null
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
*/
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import com.kunzisoft.encrypt.HashManager
|
||||
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
|
||||
|
@ -886,12 +885,9 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
|||
}
|
||||
|
||||
companion object {
|
||||
val TYPE = DatabaseKDBX::class.java
|
||||
private val TAG = DatabaseKDBX::class.java.name
|
||||
|
||||
private const val DEFAULT_HISTORY_MAX_ITEMS = 10 // -1 unlimited
|
||||
private const val DEFAULT_HISTORY_MAX_SIZE = (6 * 1024 * 1024).toLong() // -1 unlimited
|
||||
|
||||
const val BASE_64_FLAG = Base64.NO_WRAP
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
*/
|
||||
package com.kunzisoft.keepass.database.file.input
|
||||
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import com.kunzisoft.encrypt.StreamCipher
|
||||
import com.kunzisoft.keepass.database.crypto.CipherEngine
|
||||
|
@ -29,7 +28,6 @@ import com.kunzisoft.keepass.database.element.*
|
|||
import com.kunzisoft.keepass.database.element.binary.BinaryData
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX.Companion.BASE_64_FLAG
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
|
@ -47,6 +45,7 @@ import com.kunzisoft.keepass.stream.HashedBlockInputStream
|
|||
import com.kunzisoft.keepass.stream.HmacBlockInputStream
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||
import com.kunzisoft.keepass.utils.*
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import org.xmlpull.v1.XmlPullParserException
|
||||
import org.xmlpull.v1.XmlPullParserFactory
|
||||
|
@ -55,7 +54,10 @@ import java.io.InputStream
|
|||
import java.io.UnsupportedEncodingException
|
||||
import java.nio.charset.Charset
|
||||
import java.text.ParseException
|
||||
import java.util.*
|
||||
import java.util.Arrays
|
||||
import java.util.Date
|
||||
import java.util.Stack
|
||||
import java.util.UUID
|
||||
import java.util.zip.GZIPInputStream
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.CipherInputStream
|
||||
|
@ -346,7 +348,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
|||
} else if (name.equals(DatabaseKDBXXML.ElemHeaderHash, ignoreCase = true)) {
|
||||
val encodedHash = readString(xpp)
|
||||
if (encodedHash.isNotEmpty() && hashOfHeader != null) {
|
||||
val hash = Base64.decode(encodedHash, BASE_64_FLAG)
|
||||
val hash = Base64.decodeBase64(encodedHash)
|
||||
if (!Arrays.equals(hash, hashOfHeader)) {
|
||||
throw DatabaseInputException()
|
||||
}
|
||||
|
@ -432,7 +434,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
|||
} else if (name.equals(DatabaseKDBXXML.ElemCustomIconItemData, ignoreCase = true)) {
|
||||
val strData = readString(xpp)
|
||||
if (strData.isNotEmpty()) {
|
||||
customIconData = Base64.decode(strData, BASE_64_FLAG)
|
||||
customIconData = Base64.decodeBase64(strData)
|
||||
}
|
||||
} else if (name.equals(DatabaseKDBXXML.ElemName, ignoreCase = true)) {
|
||||
customIconName = readString(xpp)
|
||||
|
@ -836,7 +838,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
|||
// Catch with null test below
|
||||
}
|
||||
} else {
|
||||
var buf = Base64.decode(sDate, BASE_64_FLAG)
|
||||
var buf = Base64.decodeBase64(sDate)
|
||||
if (buf.size != 8) {
|
||||
val buf8 = ByteArray(8)
|
||||
System.arraycopy(buf, 0, buf8, 0, min(buf.size, 8))
|
||||
|
@ -902,7 +904,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
|||
}
|
||||
|
||||
return try {
|
||||
val buf = Base64.decode(encoded, BASE_64_FLAG)
|
||||
val buf = Base64.decodeBase64(encoded)
|
||||
bytes16ToUuid(buf)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to read base 64 UUID, create a random one", e)
|
||||
|
@ -1022,7 +1024,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
|||
isRAMSufficient.invoke(base64.length.toLong()), compressed, protected, binaryId)
|
||||
try {
|
||||
binaryAttachment.getOutputDataStream(mDatabase.binaryCache).use { outputStream ->
|
||||
outputStream.write(Base64.decode(base64, BASE_64_FLAG))
|
||||
outputStream.write(Base64.decodeBase64(base64))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to read base 64 attachment", e)
|
||||
|
@ -1055,7 +1057,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
|
|||
if (xpp.attributeCount > 0) {
|
||||
val protect = xpp.getAttributeValue(null, DatabaseKDBXXML.AttrProtected)
|
||||
if (protect != null && protect.equals(DatabaseKDBXXML.ValTrue, ignoreCase = true)) {
|
||||
Base64.decode(xpp.safeNextText(), BASE_64_FLAG)?.let { data ->
|
||||
Base64.decodeBase64(xpp.safeNextText())?.let { data ->
|
||||
return randomStream?.processBytes(data)
|
||||
}
|
||||
return ByteArray(0)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
*/
|
||||
package com.kunzisoft.keepass.database.file.output
|
||||
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import android.util.Xml
|
||||
import com.kunzisoft.encrypt.StreamCipher
|
||||
|
@ -28,7 +27,6 @@ import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory
|
|||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX.Companion.BASE_64_FLAG
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.database.element.entry.AutoType
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
|
@ -45,11 +43,13 @@ import com.kunzisoft.keepass.database.file.DateKDBXUtil
|
|||
import com.kunzisoft.keepass.stream.HashedBlockOutputStream
|
||||
import com.kunzisoft.keepass.stream.HmacBlockOutputStream
|
||||
import com.kunzisoft.keepass.utils.*
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.xmlpull.v1.XmlSerializer
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
import java.util.Stack
|
||||
import java.util.UUID
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.CipherOutputStream
|
||||
|
@ -216,7 +216,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
|
|||
writeString(DatabaseKDBXXML.ElemGenerator, mDatabaseKDBX.localizedAppName)
|
||||
|
||||
if (hashOfHeader != null) {
|
||||
writeString(DatabaseKDBXXML.ElemHeaderHash, String(Base64.encode(hashOfHeader!!, BASE_64_FLAG)))
|
||||
writeString(DatabaseKDBXXML.ElemHeaderHash, String(Base64.encodeBase64(hashOfHeader!!)))
|
||||
}
|
||||
|
||||
if (!header!!.version.isBefore(FILE_VERSION_40)) {
|
||||
|
@ -417,7 +417,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
|
|||
writeString(name, DatabaseKDBXXML.DateFormatter.format(date))
|
||||
} else {
|
||||
val buf = longTo8Bytes(DateKDBXUtil.convertDateToKDBX4Time(date))
|
||||
val b64 = String(Base64.encode(buf, BASE_64_FLAG))
|
||||
val b64 = String(Base64.encodeBase64(buf))
|
||||
writeString(name, b64)
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
|
|||
@Throws(IllegalArgumentException::class, IllegalStateException::class, IOException::class)
|
||||
private fun writeUuid(name: String, uuid: UUID) {
|
||||
val data = uuidTo16Bytes(uuid)
|
||||
writeString(name, String(Base64.encode(data, BASE_64_FLAG)))
|
||||
writeString(name, String(Base64.encodeBase64(data)))
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -490,7 +490,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
|
|||
// Write the XML
|
||||
binary.getInputDataStream(binaryCache).use { inputStream ->
|
||||
inputStream.readAllBytes { buffer ->
|
||||
xml.text(String(Base64.encode(buffer, BASE_64_FLAG)))
|
||||
xml.text(String(Base64.encodeBase64(buffer)))
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -562,7 +562,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
|
|||
xml.attribute(null, DatabaseKDBXXML.AttrProtected, DatabaseKDBXXML.ValTrue)
|
||||
val data = value.toString().toByteArray()
|
||||
val encoded = randomStream?.processBytes(data) ?: ByteArray(0)
|
||||
xml.text(String(Base64.encode(encoded, BASE_64_FLAG)))
|
||||
xml.text(String(Base64.encodeBase64(encoded)))
|
||||
} else {
|
||||
xml.text(value.toString())
|
||||
}
|
||||
|
@ -723,7 +723,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
|
|||
Log.e(TAG, "Unable to write custom icon", e)
|
||||
} finally {
|
||||
writeString(DatabaseKDBXXML.ElemCustomIconItemData,
|
||||
String(Base64.encode(customImageData, BASE_64_FLAG)))
|
||||
String(Base64.encodeBase64(customImageData)))
|
||||
}
|
||||
if (iconCustom.name.isNotEmpty()) {
|
||||
writeString(DatabaseKDBXXML.ElemName, iconCustom.name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue