SceneGate / Ekona

.NET implementation of DS and DSi file formats
https://scenegate.github.io/Ekona/
MIT License
28 stars 1 forks source link

:sparkles: Implement DS secure area (de)encryption (KEY1) and validate/generate hashes #19

Closed pleonex closed 2 years ago

pleonex commented 2 years ago

Description

Example

To use the KEY1 encryption alone use the class NitroBlowfish:

var blowfish = new NitroBlowfish();
blowfish.Initialize(gameCode, level, modulo, key);

uint data0, data1;
byte[] dataArray;
Stream dataStream;

blowfish.Decrypt(ref data0, ref data1); // or Encrypt()
byte[] output = blowfish.Decrypt(dataArray); // or Encrypt()
blowfish.Decrypt(dataStream); // or Encrypt()

To encrypt or decrypt the ARM9 use the class NitroKey1Encryption:

var encryption = new NitroKey1Encryption(gameCode, keys);
bool isEncrypted = encryption.HasEncryptedArm9(arm9Stream); // false in game dumps
using DataStream encryptedArm9 = encryption.EncryptArm9(arm9Stream);
using DataStream decryptedArm9 = encryption.DecryptArm9(encryptedArm9);

To verify or generate the "disable secure area" token use the class NitroKey1Encryption:

var encryption = new NitroKey1Encryption(gameCode, keys);
byte[] token = encryption.GenerateEncryptedDisabledSecureAreaToken();
encryption.HasDisabledSecureArea(token);