pgpkeys.pas
来自「用DELPHI实现的 PGP 加密算法」· PAS 代码 · 共 1,703 行 · 第 1/5 页
PAS
1,703 行
PGPFindKeyByKeyID7: function(KeyDB: pPGPKeyDB;
const PGPKeyID: TPGPKeyID7;
var Key: pPGPKeyDBObj): PGPError; cdecl;
// must be in format output by PGPExportKeyID
// PGP 6.5.X
PGPImportKeyID: function(const KeyID: PChar;
var PGPKeyID: TPGPKeyID7): PGPError; cdecl;
// outputs opaque string of bytes for storage of maximum size as KeyID
// PGP 6.5.X
PGPExportKeyID: function(const KeyID: PChar;
var PGPKeyID: TPGPKeyID7;
var IDLength: PGPSize): PGPError; cdecl;
// both
PGPGetKeyIDString: function(const PGPKeyID: TPGPKeyID7;
AType: PGPKeyIDStringType;
KeyID: TKeyID): PGPError; cdecl;
// PGP 6.5.X
PGPGetKeyIDFromString6: function(KeyID: PChar;
var PGPkeyID: TPGPKeyID7): PGPError; cdecl;
// PGP 7.X
PGPNewKeyIDFromString7: function(KeyID: PChar;
PubKeyAlgorithm: PGPPublicKeyAlgorithm;
var PGPkeyID: TPGPKeyID7): PGPError; cdecl;
// PGP 6.5.X
PGPGetKeyIDFromKey6: function(Key: pPGPKey;
var PGPKeyID: TPGPKeyID7): PGPError; cdecl;
// PGP 6.5.X
PGPGetKeyIDFromSubKey6: function(Key: pPGPSubKey;
var PGPKeyID: TPGPKeyID7): PGPError; cdecl;
// PGP 6.5.X
PGPGetKeyIDOfCertifier6: function(Sig: pPGPSig;
var PGPKeyID: TPGPKeyID7): PGPError; cdecl;
// PGP 7.X
PGPGetKeyID7: function(Key: pPGPKeyDBObj;
var PGPKeyID: TPGPKeyID7): PGPError; cdecl;
// both
// returns 0 if equal, -1 if Key1 < Key2, 1 if Key1 > Key2
PGPCompareKeyIDs: function(var Key: TPGPKeyID7;
var Key2: TPGPKeyID7): PGPInt32; cdecl;
{ Context retrieval functions both}
PGPGetKeySetContext: function(KeySet: pPGPKeySet): pPGPContext; cdecl;
PGPGetKeyListContext: function(KeyList: pPGPKeyList): pPGPContext; cdecl;
PGPGetKeyIterContext: function(KeyIter: pPGPKeyIter): pPGPContext; cdecl;
{ Context retrieval functions 6.5.X}
PGPGetKeyContext: function(Key: pPGPKey): pPGPContext; cdecl;
PGPGetSubKeyContext: function(SubKey: pPGPSubKey): pPGPContext; cdecl;
PGPGetUserIDContext: function(UserID: pPGPUserID): pPGPContext; cdecl;
{ Context retrieval functions 7.X}
PGPPeekKeyDBContext: function(KeyDB: pPGPKeyDB): pPGPContext; cdecl;
PGPPeekKeyDBObjContext: function(KeyDBObj: pPGPKeyDBObj): pPGPContext; cdecl;
{ Self signature options }
// PGP 6.5.X
PGPAddKeyOptions: function(Key: pPGPKey;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError; cdecl;
// PGP 7.X
{PGPAddKeyOptions: function(Key: pPGPKeyDBObj;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError; cdecl;}
// PGP 6.5.X
PGPRemoveKeyOptions: function(Key: pPGPKey;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError; cdecl;
// PGP 7.X
{PGPRemoveKeyOptions: function(Key: pPGPKeyDBObj;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError; cdecl;}
// PGP 6.5.X
PGPUpdateKeyOptions: function(Key: pPGPKey;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError; cdecl;
// PGP 7.X
{PGPUpdateKeyOptions: function(Key: pPGPKeyDBObj;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError; cdecl;}
// wrapper functions for version compatibility
function PGPRemoveKeys(KeysToRemove: pPGPKeySet;
ASet: pPGPKeySet): PGPError;
function PGPEnableKey(Key: Pointer): PGPError;
function PGPDisableKey(Key: Pointer): PGPError;
function PGPRevokeKey(Key: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPRevokeSubKey(SubKey: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPOrderKeySet(KeySet: pPGPKeySet;
Order: PGPKeyOrdering; ReverseOrder: PGPBoolean;
var KeyList: pPGPKeyList): PGPError;
function PGPKeyIterNextKeyDBObj(Iter: pPGPKeyIter;
ObjectType: PGPKeyDBObjType; var OutRef: Pointer): PGPError;
function PGPKeyIterPrevKeyDBObj(Iter: pPGPKeyIter;
ObjectType: PGPKeyDBObjType; var OutRef: Pointer): PGPError;
function PGPKeyIterRewindKeyDBObj(Iter: pPGPKeyIter; ObjectType: PGPKeyDBObjType): PGPError;
function PGPChangePassphrase(Key: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPChangeSubKeyPassphrase(SubKey: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPSetPrimaryUserID(UserID: pPGPUserID;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPRevokeSig(Cert: Pointer;
AllKeys: pPGPKeySet;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPGetIndexedAdditionalRecipientRequestKey(BaseKey: Pointer;
AllKeys: pPGPKeySet;
ARKeyIndex: PGPUInt32;
var ARKey: Pointer;
var ARKeyID: TPGPKeyID7;
var ARClass: PGPByte): PGPError;
function PGPGetIndexedRevocationKey(BaseKey: Pointer;
AllKeys: pPGPKeySet;
RevKeyIndex: PGPUInt32;
var RevKey: Pointer;
var RevKeyID: TPGPKeyID7): PGPError;
function PGPGetKeyPasskeyBuffer(Key: pPGPKey;
pPasskeyBuffer: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPGetSubKeyPasskeyBuffer(SubKey: pPGPSubKey;
pPasskeyBuffer: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
function PGPGetPrimaryUserIDNameBuffer(Key: Pointer;
UserID: PChar;
BufferSize: PGPSize;
var FullSize: PGPSize): PGPError;
function PGPGetKeyByKeyID(KeySet: pPGPKeySet;
const PGPKeyID: TPGPKeyID7;
PubKeyAlgorithm: PGPPublicKeyAlgorithm;
var Key: Pointer): PGPError;
function PGPGetKeyIDFromString(KeyID: PChar;
PubKeyAlgorithm: PGPPublicKeyAlgorithm;
var PGPkeyID: TPGPKeyID7): PGPError;
function PGPGetKeyIDFromKey(Key: pPGPKey;
var PGPKeyID: TPGPKeyID7): PGPError;
function PGPGetKeyIDFromSubKey(Key: pPGPSubKey;
var PGPKeyID: TPGPKeyID7): PGPError;
function PGPGetKeyIDOfCertifier(Sig: pPGPSig;
var PGPKeyID: TPGPKeyID7): PGPError;
function PGPNewKeyDBObjBooleanFilter(Context: pPGPContext;
WhichProperty: PGPKeyDBObjProperty; Match: PGPBoolean;
var OutFilter: pPGPFilter): PGPError;
function PGPNewKeyDBObjNumericFilter(Context: pPGPContext;
WhichProperty: PGPKeyDBObjProperty; MatchValue: PGPUInt32;
MatchCriteria: PGPMatchCriterion; var OutFilter: pPGPFilter): PGPError;
function PGPNewKeyDBObjTimeFilter(Context: pPGPContext;
WhichProperty: PGPKeyDBObjProperty; MatchValue: PGPTime;
MatchCriteria: PGPMatchCriterion; var OutFilter: pPGPFilter): PGPError;
function PGPNewKeyDBObjDataFilter(Context: pPGPContext;
WhichProperty: PGPKeyDBObjProperty; const MatchData: Pointer;
MatchDataSize: PGPSize; MatchCriteria: PGPMatchCriterion;
var OutFilter: pPGPFilter): PGPError;
function PGPGetKeyDBObjBooleanProperty(Obj: Pointer;
WhichProperty: PGPKeyDBObjProperty; var Prop: PGPBoolean): PGPError;
function PGPGetKeyDBObjNumericProperty(Obj: Pointer;
WhichProperty: PGPKeyDBObjProperty; var Prop: PGPInt32): PGPError;
function PGPGetKeyDBObjTimeProperty(Obj: Pointer;
WhichProperty: PGPKeyDBObjProperty; var Prop: PGPTime): PGPError;
function PGPGetKeyDBObjDataProperty(Obj: Pointer;
WhichProperty: PGPKeyDBObjProperty; Buffer: PChar;
BufferSize: PGPSize; var DataSize: PGPSize): PGPError;
implementation // code modified by idw
uses
Windows;
function PGPRemoveKeys(KeysToRemove: pPGPKeySet;
ASet: pPGPKeySet): PGPError;
begin
if PGP7X then
Result:=PGPDeleteKeys7(KeysToRemove)
else Result:=PGPRemoveKeys6(KeysToRemove, ASet);
end;
function PGPEnableKey(Key: Pointer): PGPError;
begin
if PGP7X
then Result:=PGPSetKeyDBObjEnabled7(pPGPKeyDBObj(Key), PGPTrue)
else Result:=PGPEnableKey6(pPGPKey(Key));
end;
function PGPDisableKey(Key: Pointer): PGPError;
begin
if PGP7X
then Result:=PGPSetKeyDBObjEnabled7(pPGPKeyDBObj(Key), PGPFalse)
else Result:=PGPDisableKey6(pPGPKey(Key));
end;
function PGPRevokeKey(Key: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
begin
if PGP7X
then Result:=PGPRevoke7(pPGPKeyDBObj(Key), Options, LastOption)
else Result:=PGPRevokeKey6(pPGPKey(Key), Options, LastOption);
end;
function PGPRevokeSubKey(SubKey: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
begin
if PGP7X
then Result:=PGPRevoke7(pPGPKeyDBObj(SubKey), Options, LastOption)
else Result:=PGPRevokeSubKey6(pPGPSubKey(SubKey), Options, LastOption);
end;
// takes PGP 7.X PGPKeyOrdering constants
function PGPOrderKeySet(KeySet: pPGPKeySet;
Order: PGPKeyOrdering; ReverseOrder: PGPBoolean;
var KeyList: pPGPKeyList): PGPError;
begin
if PGP7X then
Result:=PGPOrderKeySet7(KeySet, Order, ReverseOrder, KeyList)
else begin
if Order>kPGPKeyOrdering_Any then Order:=pred(Order) shl 1 + ReverseOrder;
Result:=PGPOrderKeySet6(KeySet, Order, KeyList);
end;
end;
// takes PGP 7.X PGPKeyDBObjType constants
function PGPKeyIterNextKeyDBObj(Iter: pPGPKeyIter;
ObjectType: PGPKeyDBObjType; var OutRef: Pointer): PGPError;
begin
if PGP7X then
Result:=PGPKeyIterNextKeyDBObj7(Iter, ObjectType, pPGPKeyDBObj(OutRef))
else begin
case ObjectType of
kPGPKeyDBObjType_Key: Result:=PGPKeyIterNext(Iter, pPGPKey(OutRef));
kPGPKeyDBObjType_SubKey: Result:=PGPKeyIterNextSubKey(Iter, pPGPSubKey(OutRef));
kPGPKeyDBObjType_UserID: Result:=PGPKeyIterNextUserID(Iter, pPGPUserID(OutRef));
kPGPKeyDBObjType_Signature: Result:=PGPKeyIterNextUIDSig(Iter, pPGPSig(OutRef));
else
Result:=kPGPError_EndOfIteration;
end;
end;
end;
// takes PGP 7.X PGPKeyDBObjType constants
function PGPKeyIterPrevKeyDBObj(Iter: pPGPKeyIter;
ObjectType: PGPKeyDBObjType; var OutRef: Pointer): PGPError;
begin
if PGP7X then
Result:=PGPKeyIterPrevKeyDBObj7(Iter, ObjectType, pPGPKeyDBObj(OutRef))
else begin
case ObjectType of
kPGPKeyDBObjType_Key: Result:=PGPKeyIterPrev(Iter, pPGPKey(OutRef));
kPGPKeyDBObjType_SubKey: Result:=PGPKeyIterPrevSubKey(Iter, pPGPSubKey(OutRef));
kPGPKeyDBObjType_UserID: Result:=PGPKeyIterPrevUserID(Iter, pPGPUserID(OutRef));
kPGPKeyDBObjType_Signature: Result:=PGPKeyIterPrevUIDSig(Iter, pPGPSig(OutRef));
else
Result:=kPGPError_EndOfIteration;
end;
end;
end;
// takes PGP 7.X PGPKeyDBObjType constants
function PGPKeyIterRewindKeyDBObj(Iter: pPGPKeyIter; ObjectType: PGPKeyDBObjType): PGPError;
begin
if PGP7X then
Result:=PGPKeyIterRewindKeyDBObj7(Iter, ObjectType)
else begin
case ObjectType of
kPGPKeyDBObjType_Key: Result:=PGPKeyIterRewind(Iter);
kPGPKeyDBObjType_SubKey: Result:=PGPKeyIterRewindSubKey(Iter);
kPGPKeyDBObjType_UserID: Result:=PGPKeyIterRewindUserID(Iter);
kPGPKeyDBObjType_Signature: Result:=PGPKeyIterRewindUIDSig(Iter);
else
Result:=kPGPError_EndOfIteration;
end;
end;
end;
function PGPChangePassphrase(Key: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
begin
if PGP7X then
Result:=PGPChangePassphrase7(pPGPKeyDBObj(Key), Options, LastOption)
else Result:=PGPChangePassphrase6(pPGPKey(Key), Options, LastOption);
end;
function PGPChangeSubKeyPassphrase(SubKey: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
begin
if PGP7X then
Result:=PGPChangePassphrase7(pPGPKeyDBObj(SubKey), Options, LastOption)
else Result:=PGPChangeSubKeyPassphrase6(pPGPSubKey(SubKey), Options, LastOption);
end;
// UserID type depends on PGP version
function PGPSetPrimaryUserID(UserID: Pointer;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
begin
if PGP7X then
Result:=PGPSetPrimaryUserID7(pPGPKeyDBObj(UserID), Options, LastOption)
else Result:=PGPSetPrimaryUserID6(pPGPUserID(UserID));
end;
// Cert type depends on PGP version
function PGPRevokeSig(Cert: Pointer;
AllKeys: pPGPKeySet;
Options: pPGPOptionList;
LastOption: pPGPOptionList): PGPError;
begin
if PGP7X then
Result:=PGPRevokeSig7(pPGPKeyDBObj(Cert), Options, LastOption)
else Result:=PGPRevokeSig6(pPGPSig(Cert), AllKeys, Options, LastOption);
end;
// BaseKey/ARKey types depend on PGP version
function PGPGetIndexedAdditionalRecipientRequestKey(BaseKey: pPGPKey;
AllKeys: pPGPKeySet;
ARKeyIndex: PGPUInt32;
var ARKey: pPGPKey;
var ARKeyID: TPGPKeyID7;
var ARClass: PGPByte): PGPError;
begin
if PGP7X then
Result:=PGPGetIndexedAdditionalRecipientRequestKey7(pPGPKeyDBObj(BaseKey), ARKeyIndex,
pPGPKeyDBObj(ARKey), ARKeyID, ARClass)
else Result:=PGPGetIndexedAdditionalRecipientRequestKey6(pPGPKey(BaseKey), AllKeys, ARKeyIndex,
pPGPKey(ARKey), ARKeyID, ARClass);
end;
// BaseKey/RevKey types depend on PGP version
function PGPGetIndexedRevocationKey(BaseKey: Pointer;
AllKeys: pPGPKeySet;
RevKeyIndex: PGPUInt32;
var RevKey: Pointer;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?