@meeco/cryppo
Version:
In-browser encryption and decryption. Clone of Ruby Cryppo
52 lines (51 loc) • 2.91 kB
TypeScript
/// <reference types="node" />
import { util } from 'node-forge';
import { IEncryptionArtifacts } from './encryption/encryption';
import { ICryppoSerializationArtifacts, IDerivedKey } from './key-derivation/derived-key';
import { SerializationFormat } from './serialization-versions';
/**
* Wrapping some node-forge utils in case we ever need to replace it
*/
export declare const encode64: typeof util.encode64;
export declare const decode64: typeof util.decode64;
export declare const encodeUtf8: typeof util.encodeUtf8;
export declare const utf8ToBytes: typeof util.text.utf8.encode;
export declare const utf16ToBytes: typeof util.text.utf16.encode;
export declare const binaryStringToBytes: typeof util.binary.raw.decode;
export declare const bytesToBinaryString: (bytes: Uint8Array) => string;
export declare const bytesToUtf16: (bytes: Uint8Array) => string;
export declare const bytesToUtf8: (bytes: Uint8Array) => string;
export declare const binaryStringToBytesBuffer: (value: string) => Buffer;
export declare const bytesBufferToBinaryString: (val: Buffer | Uint8Array | ArrayBuffer) => string;
export declare const generateRandomBytesString: (length?: number) => string;
export declare function serializeDerivedKeyOptions(strategy: string, artifacts: IDerivedKey | IEncryptionArtifacts | ICryppoSerializationArtifacts, serializationFormat?: SerializationFormat): string;
export declare function deSerializeDerivedKeyOptions(serialized: string): {
derivationStrategy: string;
serializationArtifacts: IEncryptionArtifacts;
};
export declare function serialize(strategy: string, data: string, artifacts: IDerivedKey | IEncryptionArtifacts, serializationFormat?: SerializationFormat): string;
export interface IDecoded {
encryptionStrategy: string;
decodedPairs: any[];
}
export declare function deSerialize(serialized: string): IDecoded;
/**
* The Ruby version uses url safe base64 encoding.
* RFC 4648 specifies + is encoded as - and / is _
* with the trailing = removed.
*/
export declare function encodeSafe64(data: string): string;
export declare function decodeSafe64(base64: string): string;
export declare function encodeSafe64Bson(versionByte: string, artifacts: IDerivedKey | IEncryptionArtifacts | ICryppoSerializationArtifacts): string;
export declare function decodeSafe64Bson(base64: string): string;
export declare function encodeDerivationArtifacts(artifacts: IDerivedKey): string;
export declare function decodeDerivationArtifacts(encoded: string): any;
/**
* Returns some base64 encoded random bytes that can be used for encryption verification.
*/
export declare function generateEncryptionVerificationArtifacts(): {
token: string;
salt: string;
};
export declare function keyLengthFromPublicKeyPem(publicKeyPem: string): any;
export declare function keyLengthFromPrivateKeyPem(privateKey: string): any;