Filename
fnAes = fnInput;
fnAes.
SetSuffix
(
"aes"
_s);
// Note: Password needs to be either 16, 24, or 32 characters long.
const
char
pw[] = {
's'
,
'p'
,
'e'
,
'a'
,
'k'
,
','
,
' '
,
'f'
,
'r'
,
'i'
,
'e'
,
'n'
,
'd'
,
','
,
' '
,
'a'
,
'n'
,
'd'
,
' '
,
'e'
,
'n'
,
't'
,
'e'
,
'r'
};
const
Int32
keylen =
sizeof
(pw) * 8;
// keylen is in bits
DebugAssert
((keylen == 128) || (keylen == 192) || (keylen == 256));
const
Int32
blocksize = 256;
if
(!fileAes->
Open
(fnAes, pw, keylen, blocksize, 0,
FILEOPEN::WRITE
))
{
return
maxon::IoError(
MAXON_SOURCE_LOCATION
,
MaxonConvert
(fnAes,
MAXONCONVERTMODE::NONE
),
"Error: Failed to open AES file for writing."
_s);
}
const
Int
fileSize = fileInput->
GetLength
();
Char
* buffer =
NewMemClear
(
Char
, fileSize)
iferr_return
;
const
Int
readBytes = fileInput->
TryReadBytes
(buffer, fileSize);
if
(readBytes != fileSize)
{
return
maxon::UnexpectedError(
MAXON_SOURCE_LOCATION
,
"Error: Failed to read data from input file."
_s);
}
if
(!fileAes->
WriteBytes
(buffer, fileSize))
{
return
maxon::UnexpectedError(
MAXON_SOURCE_LOCATION
,
"Error: Failed to write data to AES file."
_s);
}
fileAes->
关闭
();
fileInput->
关闭
();
// Finally check the encryption result.
if
(
AESFile::CheckEncryption
(fnAes, fnInput, pw, keylen, blocksize))
{
ApplicationOutput
(
"Success: The encrypted file matches the encrypted version."
_s);
return
maxon::OK
;
}
else
{
return
maxon::UnexpectedError(
MAXON_SOURCE_LOCATION
,
"Error: The encrypted file does not match the encrypted version."
_s);
}
Allocation/Deallocation
AESFile
objects are created with the usual tools, see
Entity Creation and Destruction Manual (Classic)
.
Open
-
警告
-
For a plugin to be cross platform then the type and creator parameters must be correctly filled for Mac.
杂项
延伸阅读
Int TryReadBytes(void *data, Int len)
maxon::Int Int
定义:
ge_sys_math.h:62
#define MACTYPE_CINEMA
Standard Mac type code for Cinema 4D.
定义:
ge_prepass.h:30
#define NewMemClear(T, cnt)
定义:
defaultallocator.h:205
@ ANY
Show an error dialog for any error.
static Bool CheckEncryption(const Filename &encrypt, const Filename &decrypt, const char *key, Int32 keylen, Int32 blocksize)
@ V_INTEL
Intel, little endian.
Manages file and path names.
定义:
c4d_file.h:93
return OK
定义:
apibase.h:2532
@ NONE
No check if file exists under case-sensitive drives.
#define iferr_return
定义:
resultbase.h:1434
#define MAXON_SOURCE_LOCATION
定义:
memoryallocationbase.h:66
Bool Open(const Filename &name, FILEOPEN mode=FILEOPEN::READ, FILEDIALOG error_dialog=FILEDIALOG::IGNOREOPEN, BYTEORDER order=BYTEORDER::V_MOTOROLA, Int32 type='C4DC', Int32 creator='C4D1')
void SetSuffix(const maxon::String &str)
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
Bool WriteBytes(const void *data, Int len)
Bool Open(const Filename &name, const char *key, Int32 keylen, Int32 blocksize, UInt32 aes_flags, FILEOPEN mode=FILEOPEN::READ, FILEDIALOG error_dialog=FILEDIALOG::IGNOREOPEN, BYTEORDER order=BYTEORDER::V_MOTOROLA, Int32 type='C4DC', Int32 creator='C4D1')
maxon::Int32 Int32
定义:
ge_sys_math.h:58
#define ApplicationOutput(formatString,...)
定义:
debugdiagnostics.h:207
#define MACCREATOR_CINEMA
Standard Mac creator code for Cinema 4D.
定义:
ge_prepass.h:31
@ READ
Open the file for reading.
#define DebugAssert(condition,...)
定义:
debugdiagnostics.h:245
maxon::Char Char
定义:
ge_sys_math.h:54
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())