private bool checkNPDHash2(byte[] klicensee, byte[] npd) { byte[] xoredKey = new byte[0x10]; ToolsImpl.XOR(xoredKey, klicensee, EDATKeys.npdrm_omac_key2); byte[] calculated = ToolsImpl.CMAC128(xoredKey, npd, 0, 0x60); bool result2 = compareBytes(calculated, 0, npd, 0x60, 0x10); if (result2) { Console.WriteLine("NPD hash 2 is valid (" + ConversionUtils.getHexString(calculated) + ")"); } return(result2); }
/* KDSBEST END */ public int decryptFile(String inFile, String outFile, byte[] devKLic, byte[] keyFromRif) { FileStream fin = File.Open(inFile, FileMode.Open); string[] fn = fin.Name.Split('\\'); //string[] fn = fin.Name.Split('/'); Console.WriteLine(fn[fn.Length - 1]); NPD[] ptr = new NPD[1]; //Ptr to Ptr int result = validateNPD(fn[fn.Length - 1], devKLic, ptr, fin); //Validate NPD hashes if (result < 0) { fin.Close(); return(result); } NPD npd = ptr[0]; EDATData data = getEDATData(fin); //Get flags, blocksize and file len byte[] rifkey = getKey(npd, data, devKLic, keyFromRif); //Obtain the key for decryption (result of sc471 or sdatkey) if (rifkey == null) { Console.WriteLine("ERROR: Key for decryption is missing"); fin.Close(); return(STATUS_ERROR_MISSINGKEY); } else { Console.WriteLine("DECRYPTION KEY: " + ConversionUtils.getHexString(rifkey)); } result = checkHeader(rifkey, data, npd, fin); if (result < 0) { fin.Close(); return(result); } FileStream o = File.Open(outFile, FileMode.Create); result = decryptData(fin, o, npd, data, rifkey); if (result < 0) { fin.Close(); return(result); } fin.Close(); o.Close(); Console.WriteLine("COMPLETE: File Written to disk"); return(STATUS_OK); }
public void doInit(int hashFlag, int cryptoFlag, byte[] key, byte[] iv, byte[] hashKey) { byte[] calculatedKey = new byte[key.Length]; byte[] calculatedIV = new byte[iv.Length]; byte[] calculatedHash = new byte[hashKey.Length]; getCryptoKeys(cryptoFlag, calculatedKey, calculatedIV, key, iv); getHashKeys(hashFlag, calculatedHash, hashKey); setDecryptor(cryptoFlag); setHash(hashFlag); Debug.WriteLine("ERK: " + ConversionUtils.getHexString(calculatedKey)); Debug.WriteLine("IV: " + ConversionUtils.getHexString(calculatedIV)); Debug.WriteLine("HASH: " + ConversionUtils.getHexString(calculatedHash)); dec.doInit(calculatedKey, calculatedIV); hash.doInit(calculatedHash); }
private bool checkNPDHash1(String filename, byte[] npd) { byte[] fileBytes = ConversionUtils.charsToByte(filename.ToCharArray()); byte[] data1 = new byte[0x30 + fileBytes.Length]; ConversionUtils.arraycopy(npd, 0x10, data1, 0, 0x30); ConversionUtils.arraycopy(fileBytes, 0x00, data1, 0x30, fileBytes.Length); byte[] hash1 = ToolsImpl.CMAC128(EDATKeys.npdrm_omac_key3, data1, 0, data1.Length); bool result1 = compareBytes(hash1, 0, npd, 0x50, 0x10); if (result1) { Console.WriteLine("NPD hash 1 is valid (" + ConversionUtils.getHexString(hash1) + ")"); } return(result1); }