Skip to content

Instantly share code, notes, and snippets.

@austbot austbot/sercret_service.ts
Last active Feb 19, 2018

What would you like to do?
import { Injectable, Inject } from '@angular/core';
export class SecretService {
constructor( @Inject('ENcRYPTI0n_k3y') private key: string, private features: FeatureFlags) {}
//public api
encode(secret: string) {
return SecretService._encodeSecret(this.key, secret);
//private api
static _mapToKeyChar(key: string, char: str, index: number) {
const len = key.length;
const dist = index > len-1 ? index - len : len - index;
return key[dist];
static _encodeSecret(key: string, secret: string) {
return secret
.map((char, index, str) => {
return SecretService._mapToKeyChar(key, char, index);
function createService(key, flags) {
const featureFlags = new FeatureFlags(flags) //imaging flags is an object {"feature1": false ...
return new SecretService(key, featureFlags);
describe('Secret Service', () => {
it('uses better encryption when its on', () => {
const svc = createService("key", {'more_entropy': true}); //Create a 'context'
const result =; //Test the function at that 'context'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.