jwt_generator 0.0.1 copy "jwt_generator: ^0.0.1" to clipboard
jwt_generator: ^0.0.1 copied to clipboard

A package for generating JWT.

JWT GENERATOR #

Overview #

This package is used for generating JWT using rsa_pkcs and pointycastle

FEATURES #

  • **JWT GENERATOR Generates JWT

Installation #

For Dart use:

dart pub add jwt_manager

For Flutter use:

flutter pub add jwt_manager

You can manually edit your pubspec.yaml file this:

dependencies:
  jwt_manager: ^0.0.1

You can run a dart pub get or flutter pub get for Dart and Flutter respectively to complete installation.

Usage #

Example:

import 'package:jwt_generator/jwt_generator.dart';

void main() { // Creating a token final tokenDto = FcmTokenDto( iss: 'some@email.com', iat: DateTime(2001), );

final pemPrivateKey = ''' -----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- '''; final pemPublicKey = ''' -----BEGIN PUBLIC KEY----- -----END PUBLIC KEY----- ''';

// Creating an encoded and signed token

// RsaKeyParser extracts private key from a pem string final parser = RsaKeyParser(); final rsaPrivateKey = parser.extractPrivateKey(pemPrivateKey);

// Create RsaSignifier for signing final rsaSignifier = RsaSignifier(privateKey: rsaPrivateKey);

// JwtBuilder encodes the token to string and signs it final jwtBuilder = JwtBuilder(signifier: rsaSignifier); final jwtToken = jwtBuilder.buildToken(tokenDto);

print('Encoded JWT: $jwtToken');

// Checking the signature with the public key

// Extract public key from a pem string final rsaPublicKey = parser.extractPublicKey(pemPublicKey);

// Verifying the signature final rsaVerifier = RsaSignatureVerifier(publicKey: rsaPublicKey); final isVerified = rsaVerifier.verify( 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzb21lQGVtYWlsLmNvbSIsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9maXJlYmFzZS5tZXNzYWdpbmciLCJhdWQiOiJodHRwczovL29hdXRoMi5nb29nbGVhcGlzLmNvbS90b2tlbiIsImV4cCI6OTc4Mjk2NDAwLCJpYXQiOjk3ODI5MjgwMH0', 'cqABcd-RMTQvxvI2zKPNek-UPd7fY0796B8hN9pDYyyrRWDOy7LlufaCvMlDIXrOS-zJMTsFbPQ8UMYY2Ofkz_lloCy4K5IhGZQIOjYvfhIZhp9PxMvj0XhRsezERQoK4air_lcUEh1LJ1o9j_i4P0XyOqGhcgcKKZLrc3zziSbb-vEIKu9gX4WsVYpyv4CK-o9AOAxXqukebcrIdURhf0V8o1hiVwTTfX5_x4j_XF99ZqjoFCTTcieM2F7F9-LFmwqy9Cg0E_UsyPC7aeR_UADLfE-1SBfYTSPdxAZ0HVfYQcET7hnzZJzz_NhyD62fLQzj6Eqag8_fWeZr_NYsPg');

print('Is signature verified: $isVerified'); }

0
likes
0
points
452
downloads

Publisher

unverified uploader

Weekly Downloads

A package for generating JWT.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

pointycastle, rsa_pkcs

More

Packages that depend on jwt_generator